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 pathBuildVersionSetDriver.cs
More file actions
110 lines (91 loc) · 4.12 KB
/
BuildVersionSetDriver.cs
File metadata and controls
110 lines (91 loc) · 4.12 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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.
namespace NuGet.Insights.Worker.BuildVersionSet
{
public class BuildVersionSetDriver : ICatalogLeafScanBatchDriver
{
private readonly CatalogClient _catalogClient;
private readonly VersionSetAggregateStorageService _aggregateStorageService;
private readonly VersionSetService _versionSetService;
private readonly PackageFilter _packageFilter;
public BuildVersionSetDriver(
CatalogClient catalogClient,
VersionSetAggregateStorageService aggregateStorageService,
VersionSetService versionSetService,
PackageFilter packageFilter)
{
_catalogClient = catalogClient;
_aggregateStorageService = aggregateStorageService;
_versionSetService = versionSetService;
_packageFilter = packageFilter;
}
public async Task InitializeAsync()
{
await _versionSetService.InitializeAsync();
}
public async Task InitializeAsync(CatalogIndexScan indexScan)
{
await _aggregateStorageService.InitializeAsync(indexScan.StorageSuffix);
}
public Task<CatalogIndexScanResult> ProcessIndexAsync(CatalogIndexScan indexScan)
{
return Task.FromResult(CatalogIndexScanResult.ExpandAllLeaves);
}
public async Task<CatalogPageScanResult> ProcessPageAsync(CatalogPageScan pageScan)
{
var page = await _catalogClient.GetCatalogPageAsync(pageScan.Url);
IReadOnlyList<CatalogLeafItem> leafItems = page.GetLeavesInBounds(pageScan.Min, pageScan.Max, excludeRedundantLeaves: true);
leafItems = _packageFilter.FilterCatalogLeafItems(pageScan.ScanId, leafItems);
if (leafItems.Any())
{
var batch = new CatalogLeafBatchData(
leafItems.Max(x => x.CommitTimestamp),
leafItems
.Select(x => new CatalogLeafItemData(
x.PackageId,
x.ParsePackageVersion().ToNormalizedString(),
x.IsPackageDelete()))
.ToList());
await _aggregateStorageService.AddBatchAsync(pageScan.StorageSuffix, batch);
}
return CatalogPageScanResult.Processed;
}
public Task<BatchMessageProcessorResult<CatalogLeafScan>> ProcessLeavesAsync(IReadOnlyList<CatalogLeafScan> leafScans)
{
throw new NotSupportedException();
}
public async Task StartAggregateAsync(CatalogIndexScan indexScan)
{
var descendingBatches = await _aggregateStorageService.GetDescendingBatchesAsync(indexScan.StorageSuffix);
var idToVersionToDeleted = new CaseInsensitiveSortedDictionary<CaseInsensitiveSortedDictionary<bool>>();
foreach (var batch in descendingBatches)
{
foreach (var leaf in batch.Leaves)
{
if (!idToVersionToDeleted.TryGetValue(leaf.Id, out var versions))
{
versions = new CaseInsensitiveSortedDictionary<bool>();
idToVersionToDeleted.Add(leaf.Id, versions);
}
if (!versions.ContainsKey(leaf.Version))
{
versions.Add(leaf.Version, leaf.IsDeleted);
}
}
}
await _versionSetService.UpdateAsync(indexScan.Max, idToVersionToDeleted);
}
public Task<bool> IsAggregateCompleteAsync(CatalogIndexScan indexScan)
{
return Task.FromResult(true);
}
public async Task FinalizeAsync(CatalogIndexScan indexScan)
{
await _aggregateStorageService.DeleteTableAsync(indexScan.StorageSuffix);
}
public async Task DestroyOutputAsync()
{
await _versionSetService.DestroyAsync();
}
}
}