This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGitHubUsageRecord.cs
More file actions
83 lines (67 loc) · 2.75 KB
/
GitHubUsageRecord.cs
File metadata and controls
83 lines (67 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.ComponentModel.DataAnnotations;
namespace NuGet.Insights.Worker.GitHubUsageToCsv
{
[CsvRecord]
public partial record GitHubUsageRecord : IAuxiliaryFileCsvRecord<GitHubUsageRecord>
{
[KustoIgnore]
public DateTimeOffset AsOfTimestamp { get; set; }
[BucketKey]
[KustoPartitionKey]
public string LowerId { get; set; }
public string Id { get; set; }
[Required]
public GitHubUsageResultType ResultType { get; set; }
/// <remarks>
/// Will be an empty string when <see cref="ResultType"/> is <see cref="GitHubUsageResultType.NoGitHubDependent"/>.
/// </remarks>
public string Repository { get; set; }
public int? Stars { get; set; }
public static IEqualityComparer<GitHubUsageRecord> KeyComparer => GitHubUsageRecordKeyComparer.Instance;
public static IReadOnlyList<string> KeyFields { get; } = [nameof(LowerId), nameof(Repository)];
public int CompareTo(GitHubUsageRecord other)
{
var c = string.CompareOrdinal(LowerId, other.LowerId);
if (c != 0)
{
return c;
}
return string.Compare(Repository, other.Repository, StringComparison.OrdinalIgnoreCase);
}
public static List<GitHubUsageRecord> Prune(
List<GitHubUsageRecord> records,
bool isFinalPrune,
IOptions<NuGetInsightsWorkerSettings> options,
ILogger logger)
{
// no duplicates are expected
return records.Order().ToList();
}
public class GitHubUsageRecordKeyComparer : IEqualityComparer<GitHubUsageRecord>
{
public static GitHubUsageRecordKeyComparer Instance { get; } = new GitHubUsageRecordKeyComparer();
public bool Equals(GitHubUsageRecord x, GitHubUsageRecord y)
{
if (ReferenceEquals(x, y))
{
return true;
}
if (x is null || y is null)
{
return false;
}
return x.LowerId == y.LowerId
&& string.Equals(x.Repository, y.Repository, StringComparison.OrdinalIgnoreCase);
}
public int GetHashCode([DisallowNull] GitHubUsageRecord obj)
{
var hashCode = new HashCode();
hashCode.Add(obj.LowerId);
hashCode.Add(obj.Repository, StringComparer.OrdinalIgnoreCase);
return hashCode.ToHashCode();
}
}
}
}