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 pathVerifiedPackagesToCsvUpdater.cs
More file actions
94 lines (83 loc) · 3.64 KB
/
VerifiedPackagesToCsvUpdater.cs
File metadata and controls
94 lines (83 loc) · 3.64 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
84
85
86
87
88
89
90
91
92
93
94
// 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 NuGet.Insights.Worker.AuxiliaryFileUpdater;
using NuGet.Insights.Worker.BuildVersionSet;
namespace NuGet.Insights.Worker.VerifiedPackagesToCsv
{
public class VerifiedPackagesToCsvUpdater : IAuxiliaryFileUpdater<AsOfData<VerifiedPackage>, VerifiedPackageRecord>
{
private readonly VerifiedPackagesClient _client;
private readonly IOptions<NuGetInsightsWorkerSettings> _options;
public VerifiedPackagesToCsvUpdater(
VerifiedPackagesClient client,
IOptions<NuGetInsightsWorkerSettings> options)
{
_client = client;
_options = options;
}
public string OperationName => "VerifiedPackagesToCsv";
public string Title => CatalogScanDriverMetadata.HumanizeCodeName(OperationName);
public string ContainerName => _options.Value.VerifiedPackageContainerName;
public TimerFrequency Frequency => TimerFrequency.Parse(_options.Value.VerifiedPackagesToCsvFrequency);
public bool HasRequiredConfiguration => _options.Value.VerifiedPackagesV1Urls is not null && _options.Value.VerifiedPackagesV1Urls.Count > 0;
public bool AutoStart => _options.Value.AutoStartVerifiedPackagesToCsv;
public async Task<AsOfData<VerifiedPackage>> GetDataAsync()
{
return await _client.GetAsync();
}
public async IAsyncEnumerable<IReadOnlyList<VerifiedPackageRecord>> ProduceRecordsAsync(IVersionSet versionSet, AsOfData<VerifiedPackage> data)
{
var verifiedPackageIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
await foreach (IReadOnlyList<VerifiedPackage> page in data.Pages)
{
foreach (VerifiedPackage entry in page)
{
var id = entry.Id;
if (!versionSet.TryGetId(entry.Id, out id))
{
continue;
}
verifiedPackageIds.Add(id);
}
}
const int pageSize = AsOfData<VerifiedPackageRecord>.DefaultPageSize;
var outputPage = new List<VerifiedPackageRecord>(capacity: pageSize);
foreach (var packageId in verifiedPackageIds)
{
outputPage.Add(new VerifiedPackageRecord
{
AsOfTimestamp = data.AsOfTimestamp,
Id = packageId,
LowerId = packageId.ToLowerInvariant(),
IsVerified = true,
});
if (outputPage.Count >= pageSize)
{
yield return outputPage;
outputPage.Clear();
}
}
// Add IDs that are not mentioned in the data and therefore are not verified. This makes joins on the
// produced data set easier.
foreach (var id in versionSet.GetUncheckedIds())
{
outputPage.Add(new VerifiedPackageRecord
{
AsOfTimestamp = data.AsOfTimestamp,
Id = id,
LowerId = id.ToLowerInvariant(),
IsVerified = false,
});
if (outputPage.Count >= pageSize)
{
yield return outputPage;
outputPage.Clear();
}
}
if (outputPage.Count > 0)
{
yield return outputPage;
}
}
}
}