Use paged CultCache trial stores
This commit is contained in:
parent
bb2d0d4864
commit
604e8312db
3 changed files with 43 additions and 9 deletions
|
|
@ -87,12 +87,12 @@ public static class IpaTrialResultCultCacheStore
|
|||
|
||||
public static async Task<IReadOnlyList<IpaTrialResult>> ReadResultsAsync(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
if (!StoreExists(filePath))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
using var cache = await CultCacheMessagePack.OpenAsync(filePath).ConfigureAwait(false);
|
||||
using var cache = await OpenTrialStoreAsync(filePath, pullOnOpen: true).ConfigureAwait(false);
|
||||
return cache.GetAll<IpaTrialResult>()
|
||||
.OrderBy(result => result.TrialId, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
|
@ -100,12 +100,12 @@ public static class IpaTrialResultCultCacheStore
|
|||
|
||||
public static async Task<IReadOnlyList<SongChallengeEvidenceDocument>> ReadSongChallengeEvidenceAsync(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
if (!StoreExists(filePath))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
using var cache = await CultCacheMessagePack.OpenAsync(filePath).ConfigureAwait(false);
|
||||
using var cache = await OpenTrialStoreAsync(filePath, pullOnOpen: true).ConfigureAwait(false);
|
||||
return cache.GetAll<SongChallengeEvidenceDocument>()
|
||||
.OrderBy(document => document.EvidenceId, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
|
@ -113,12 +113,12 @@ public static class IpaTrialResultCultCacheStore
|
|||
|
||||
public static async Task<IReadOnlyList<SongTrialDistillationDocument>> ReadSongTrialDistillationsAsync(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
if (!StoreExists(filePath))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
using var cache = await CultCacheMessagePack.OpenAsync(filePath).ConfigureAwait(false);
|
||||
using var cache = await OpenTrialStoreAsync(filePath, pullOnOpen: true).ConfigureAwait(false);
|
||||
return cache.GetAll<SongTrialDistillationDocument>()
|
||||
.OrderBy(document => document.DistillationId, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
|
@ -136,9 +136,7 @@ public static class IpaTrialResultCultCacheStore
|
|||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
using var cache = await CultCacheMessagePack.OpenAsync(
|
||||
filePath,
|
||||
new CultCacheOpenOptions { PullOnOpen = File.Exists(filePath) }).ConfigureAwait(false);
|
||||
using var cache = await OpenTrialStoreAsync(filePath, pullOnOpen: StoreExists(filePath)).ConfigureAwait(false);
|
||||
foreach (var document in documents)
|
||||
{
|
||||
await cache.UpsertAsync(document, new CultRecordHandle<T>(new CultRecordKey(key(document)))).ConfigureAwait(false);
|
||||
|
|
@ -146,4 +144,17 @@ public static class IpaTrialResultCultCacheStore
|
|||
|
||||
await cache.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static Task<CultCache> OpenTrialStoreAsync(string filePath, bool pullOnOpen) =>
|
||||
CultCacheMessagePack.OpenAsync(
|
||||
filePath,
|
||||
new CultCacheOpenOptions
|
||||
{
|
||||
PullOnOpen = pullOnOpen,
|
||||
UseDirectoryStore = true
|
||||
});
|
||||
|
||||
private static bool StoreExists(string filePath) =>
|
||||
File.Exists(filePath) ||
|
||||
Directory.Exists(DirectoryMessagePackBackingStore.DefaultRecordDirectoryPath(filePath));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue