Importazione e dati: «Tieni il più grande» per gruppi, righe di _febe.jsonl mai perse, ricostruzione robusta (import-1, import-2, library-1, journal-1, rebuild-1, rebuild-2, rebuild-3, backup-1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
13 files changed
+1145
-95
No files matched your search
@@ -127,6 +127,7 @@ public sealed class DownloadQueue
|
||||
public async Task<DownloadReport> RunOnceAsync(CancellationToken ct)
|
||||
{
|
||||
Directory.CreateDirectory(_options.StagingFolder);
|
||||
await _ingest.AppendPendingJournalAsync(ct).ConfigureAwait(false); // lines a busy _febe.jsonl refused earlier
|
||||
var tally = new Tally();
|
||||
var attempted = new ConcurrentDictionary<long, bool>();
|
||||
var accounts = new ConcurrentDictionary<long, Account?>();
|
||||
@@ -168,6 +169,15 @@ public sealed class DownloadQueue
|
||||
}
|
||||
|
||||
private async Task ProcessAsync(PendingDownload pending, Tally tally, ConcurrentDictionary<long, Account?> accounts, ConcurrentDictionary<long, bool> singlePostQueued, CancellationToken ct)
|
||||
{
|
||||
await ProcessFileAsync(pending, tally, accounts, singlePostQueued, ct).ConfigureAwait(false);
|
||||
|
||||
// Whatever the outcome (stored, duplicate, skipped, failed), the entry may now be settled: its journal line is
|
||||
// written once no file waits any more and at least one is in the library (spec §8.5).
|
||||
await AppendJournalWhenSettledAsync(pending.Media.EntryId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task ProcessFileAsync(PendingDownload pending, Tally tally, ConcurrentDictionary<long, Account?> accounts, ConcurrentDictionary<long, bool> singlePostQueued, CancellationToken ct)
|
||||
{
|
||||
var media = pending.Media;
|
||||
if (!accounts.TryGetValue(pending.AccountId, out var account))
|
||||
@@ -319,7 +329,6 @@ public sealed class DownloadQueue
|
||||
{
|
||||
tally.Add(ref tally.Stored);
|
||||
Report(media, entry, DownloadStep.Stored);
|
||||
await AppendJournalWhenCompleteAsync(entry, ct).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -393,12 +402,17 @@ public sealed class DownloadQueue
|
||||
Report(media, entry, DownloadStep.Expired);
|
||||
}
|
||||
|
||||
private async Task AppendJournalWhenCompleteAsync(Entry entry, CancellationToken ct)
|
||||
/// <summary>
|
||||
/// Appends the journal line of an entry once settled. A journal that cannot be written now (a sync client holding
|
||||
/// <c>_febe.jsonl</c>, a share that dropped) never turns a stored file back into one to download: the line waits
|
||||
/// in <see cref="LibraryIngest.TryAppendJournalAsync"/> and is written by a later pass.
|
||||
/// </summary>
|
||||
private async Task AppendJournalWhenSettledAsync(long entryId)
|
||||
{
|
||||
var files = await _storage.Media.ListByEntryAsync(entry.Id, ct).ConfigureAwait(false);
|
||||
if (files.All(f => f.State is not (MediaState.ToDownload or MediaState.Expired)))
|
||||
var files = await _storage.Media.ListByEntryAsync(entryId, CancellationToken.None).ConfigureAwait(false);
|
||||
if (files.Any(f => EntryStateRules.IsPresent(f.State)) && files.All(f => f.State is not (MediaState.ToDownload or MediaState.Expired)))
|
||||
{
|
||||
await _ingest.AppendJournalAsync(entry.Id, ct).ConfigureAwait(false);
|
||||
await _ingest.TryAppendJournalAsync(entryId, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user