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 pathLatestPackageLeafStorageFactory.cs
More file actions
75 lines (64 loc) · 2.7 KB
/
LatestPackageLeafStorageFactory.cs
File metadata and controls
75 lines (64 loc) · 2.7 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
// 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.StorageNoOpRetry;
namespace NuGet.Insights.Worker.LoadLatestPackageLeaf
{
public class LatestPackageLeafStorageFactory : ILatestPackageLeafStorageFactory<LatestPackageLeaf>
{
private readonly LatestPackageLeafService _service;
public LatestPackageLeafStorageFactory(LatestPackageLeafService service)
{
_service = service;
}
public async Task InitializeAsync()
{
await _service.InitializeAsync();
}
public async Task DestroyAsync()
{
await _service.DestroyAsync();
}
public async Task<ILatestPackageLeafStorage<LatestPackageLeaf>> CreateAsync(CatalogPageScan pageScan, IReadOnlyDictionary<ICatalogLeafItem, int> leafItemToRank)
{
return new LatestPackageLeafStorage(
await _service.GetTableAsync(),
leafItemToRank,
pageScan.Rank,
pageScan.Url);
}
private class LatestPackageLeafStorage : ILatestPackageLeafStorage<LatestPackageLeaf>
{
private readonly IReadOnlyDictionary<ICatalogLeafItem, int> _leafItemToRank;
private readonly int _pageRank;
private readonly string _pageUrl;
public LatestPackageLeafStorage(
TableClientWithRetryContext table,
IReadOnlyDictionary<ICatalogLeafItem, int> leafItemToRank,
int pageRank,
string pageUrl)
{
Table = table;
_leafItemToRank = leafItemToRank;
_pageRank = pageRank;
_pageUrl = pageUrl;
}
public TableClientWithRetryContext Table { get; }
public string CommitTimestampColumnName => nameof(LatestPackageLeaf.CommitTimestamp);
public EntityUpsertStrategy Strategy => EntityUpsertStrategy.ReadThenAdd;
public (string PartitionKey, string RowKey) GetKey(ICatalogLeafItem item)
{
return (LatestPackageLeaf.GetPartitionKey(item.PackageId), LatestPackageLeaf.GetRowKey(item.PackageVersion));
}
public Task<LatestPackageLeaf> MapAsync(string partitionKey, string rowKey, ICatalogLeafItem item)
{
return Task.FromResult(new LatestPackageLeaf(
item,
partitionKey,
rowKey,
_leafItemToRank[item],
_pageRank,
_pageUrl));
}
}
}
}