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 pathBucketedPackageStorageFactory.cs
More file actions
58 lines (47 loc) · 2.09 KB
/
BucketedPackageStorageFactory.cs
File metadata and controls
58 lines (47 loc) · 2.09 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
// 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.LoadBucketedPackage
{
public class BucketedPackageStorageFactory : ILatestPackageLeafStorageFactory<BucketedPackage>
{
private readonly BucketedPackageService _service;
public BucketedPackageStorageFactory(BucketedPackageService service)
{
_service = service;
}
public async Task InitializeAsync()
{
await _service.InitializeAsync();
}
public async Task<ILatestPackageLeafStorage<BucketedPackage>> CreateAsync(CatalogPageScan pageScan, IReadOnlyDictionary<ICatalogLeafItem, int> leafItemToRank)
{
return new BucketedPackageStorage(await _service.GetTableAsync(), pageScan.Url);
}
public async Task DestroyAsync()
{
await _service.DestroyAsync();
}
private class BucketedPackageStorage : ILatestPackageLeafStorage<BucketedPackage>
{
private readonly string _pageUrl;
public BucketedPackageStorage(TableClientWithRetryContext table, string pageUrl)
{
Table = table;
_pageUrl = pageUrl;
}
public TableClientWithRetryContext Table { get; }
public string CommitTimestampColumnName => nameof(BucketedPackage.CommitTimestamp);
public EntityUpsertStrategy Strategy => EntityUpsertStrategy.AddOptimistically;
public (string PartitionKey, string RowKey) GetKey(ICatalogLeafItem item)
{
var rowKey = BucketedPackage.GetRowKey(item);
return (BucketedPackage.GetPartitionKey(rowKey), rowKey);
}
public Task<BucketedPackage> MapAsync(string partitionKey, string rowKey, ICatalogLeafItem item)
{
return Task.FromResult(new BucketedPackage(partitionKey, rowKey, item, _pageUrl));
}
}
}
}