E5: archivio delle copie automatiche, segnale e domande 48–55

La tappa E5 copia da sola i file nuovi nelle cartelle con «Automatica».
Questo pacchetto (WP2) dà al motore che verrà ciò che gli serve dal
database, senza migrazioni:

- ExportSelection.Automatic: i file dovuti, non copiati («Tolto» e
  «Superato» mai), nuovi dal «Solo i nuovi», di elementi assestati (niente
  file da scaricare, riga del giornale scritta); i «Non riuscito» solo al
  giro di recupero, tutti e ogni giro (risposta 50 di Alberto), così un
  file che non riesce mai non fa un lavoro ogni due minuti.
- HasAutomaticCandidatesAsync, CountAutomaticBacklogAsync (la domanda
  «Copia anche gli N», i file in più, una cartella nuova), i candidati di
  «Riconosci le copie già presenti» (un «Tolto» resta «Tolto», risposta
  51) e i byte del primo file in attesa di un lavoro in pausa.
- La pausa di una destinazione si scrive solo con metodi suoi, così un
  salvataggio dall'interfaccia non la annulla; l'evento resta uno per
  passaggio.
- AutoExportSignal, un'istanza per le prove, Default per l'applicazione.

Prove nuove su un database vero, confrontate con il piano di «Copia in…»,
e misure su 200.000 elementi entro 2 s senza indici nuovi.

Documenti: in §16 le righe 48–55 con le risposte del 4 dicembre 2026 e in
decisioni.md la riga con le risposte e le tre letture del progetto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-04 13:21:56 +01:00
1 parent df50c32e22
commit f2568b5d88
12 files changed
+1212 -63

No files matched your search

+46 -5
View File
@@ -33,6 +33,10 @@ public sealed class LibraryScaleTests
// «Foto» and «Video» over the whole library: 60-180 ms measured; an EXISTS per post took 1.3-1.6 s and must fail.
private const double FilteredAggregateBoundMs = 600;
// The automatic export (tappa E5, D1): each pass and each count reads every file with the bulk terms of «Copie»,
// without an index on media.downloaded_at; 2 s each, or a migration with that index is a question for Alberto.
private const double AutomaticBoundMs = 2000;
// «Copie» over the whole library (tappa E2, WP5b): every due file is classified against the copies, 240,000 files
// at about 4 µs each; measured 0.23-1.1 s (docs/decisioni.md), «Non ancora copiati» the slowest. The design asked for
// the 600 ms of the filtered aggregates: not reachable without a column of state per file, which E2 does not add.
@@ -84,7 +88,7 @@ public sealed class LibraryScaleTests
var still = await FillStillVideosAsync(db, accountIds, ct);
fill.Stop();
TestContext.WriteLine($"Riempimento: {Entries:N0} elementi in {fill.Elapsed.TotalSeconds:F1} s");
TestContext.WriteLine($"Copie: {copies.Copied:N0} copiate (di cui {copies.Converted:N0} convertite), {copies.Removed:N0} tolte, {copies.Superseded:N0} superate, {copies.Frames:N0} fotogrammi, su {copies.Due:N0} file da copiare");
TestContext.WriteLine($"Copie: {copies.Copied:N0} copiate (di cui {copies.Converted:N0} convertite), {copies.Removed:N0} tolte, {copies.Superseded:N0} superate, {copies.Failed:N0} non riuscite, {copies.Frames:N0} fotogrammi, su {copies.Due:N0} file da copiare");
TestContext.WriteLine($"Video fermi: {still.Analyses:N0} analisi, {still.Still:N0} «Fermo» (di cui {still.Overruled:N0} superati da un algoritmo più nuovo), {still.Entries:N0} elementi e {still.Files:N0} file nel filtro");
Assert.IsGreaterThan(0, copies.Converted, "converted copies in the fill");
Assert.IsGreaterThan(0, copies.Frames, "frames in the fill");
@@ -144,7 +148,10 @@ public sealed class LibraryScaleTests
var superseded = Insert(w, "Superseded", "'e' || substr(m.sha256, 2)", "m.sha256", $"{Spread} % 3 <> 0 AND {Spread} % 100 = 2");
var frames = Insert(w, "Copied", "m.sha256", "NULL", $"m.kind = 'Video' AND {Spread} % 50 = 7", frame)
+ Insert(w, "Removed", "m.sha256", "NULL", $"m.kind = 'Video' AND {Spread} % 100 = 9", frame);
return new CopiesWorld(whole + convertedCopies, removed, superseded, DueFiles(), accountIds[OwnAccount], convertedCopies, frames);
// Tappa E5: 1 % of the files not copied failed («Non riuscito»): still «Non ancora copiati», retried by
// every round of the automatic export and left out of its passes in between.
var failed = Insert(w, "Failed", "m.sha256", "NULL", $"{Spread} % 3 <> 0 AND {Spread} % 100 = 5");
return new CopiesWorld(whole + convertedCopies, removed, superseded, DueFiles(), accountIds[OwnAccount], convertedCopies, frames, failed, general.Id, own.Id);
},
ct);
}
@@ -320,6 +327,7 @@ public sealed class LibraryScaleTests
try
{
await MeasureCopiesAsync(Measure<object>, db, accountIds, copies);
await MeasureAutomaticAsync(Measure<object>, db, copies);
}
catch (AssertFailedException e)
{
@@ -384,8 +392,41 @@ public sealed class LibraryScaleTests
}
/// <summary>
/// What the export fill wrote: copies by state (<paramref name="Copied"/> with the converted ones), the due files, the
/// account with its own folder, and of tappa E3 the converted copies and the frames (copied and «Tolto»).
/// The automatic export (tappa E5, D1 and D4): a page of candidates as a job plans them, the pre-check of a pass with
/// something and with nothing to copy (every file read), the count of the question «Copia anche gli N» for each
/// folder, and for a new folder. The counts of the two folders add up to the files not copied of the fill.
/// </summary>
private sealed record CopiesWorld(int Copied, int Removed, int Superseded, int Due, long OwnAccountId, int Converted, int Frames);
private static async Task MeasureAutomaticAsync(Func<string, double, Func<Task<object>>, Task<object>> measure, FebeDatabase db, CopiesWorld copies)
{
var round = new ExportSelection.Automatic([new(copies.GeneralId, null)], [], Round: true);
var page = (IReadOnlyList<ExportCandidate>)await measure("automatica: una pagina", AutomaticBoundMs, async () => await db.Exports.ListCandidatesAsync(round, 0, 2000));
Assert.HasCount(2000, page);
Assert.IsFalse(page.Any(c => c.AccountId == copies.OwnAccountId), "i file di un account con la sua cartella non vanno nella generale");
var pass = (IReadOnlyList<ExportCandidate>)await measure("automatica: una pagina fuori dal giro", AutomaticBoundMs, async () => await db.Exports.ListCandidatesAsync(round with { Round = false }, 0, 2000));
Assert.HasCount(2000, pass);
Assert.IsTrue((bool)await measure("automatica: c'è da copiare", AutomaticBoundMs, async () => await db.Exports.HasAutomaticCandidatesAsync(round)));
var nothingNew = round with { Destinations = [new(copies.GeneralId, new DateTimeOffset(2030, 1, 1, 0, 0, 0, TimeSpan.Zero)), new(copies.OwnId, new DateTimeOffset(2030, 1, 1, 0, 0, 0, TimeSpan.Zero))] };
Assert.IsFalse((bool)await measure("automatica: niente di nuovo", AutomaticBoundMs, async () => await db.Exports.HasAutomaticCandidatesAsync(nothingNew)));
var general = (ExportBacklog)await measure("automatica: arretrato della generale", AutomaticBoundMs, async () =>
await db.Exports.CountAutomaticBacklogAsync(new ExportBacklogQuery(ExportScope.General, null, ContentTypes.All, copies.GeneralId, null)));
var own = (ExportBacklog)await measure("automatica: arretrato di una cartella propria", AutomaticBoundMs, async () =>
await db.Exports.CountAutomaticBacklogAsync(new ExportBacklogQuery(ExportScope.Account, copies.OwnAccountId, ContentTypes.PostPhotos, copies.OwnId, null)));
var notCopied = copies.Due - copies.Copied - copies.Removed - copies.Superseded;
Assert.AreEqual(notCopied, general.Files + own.Files);
Assert.AreEqual(notCopied * 1000L, general.Bytes + own.Bytes);
Assert.IsGreaterThan(0, own.Files);
var moved = (ExportBacklog)await measure("automatica: arretrato di una cartella nuova", AutomaticBoundMs, async () =>
await db.Exports.CountAutomaticBacklogAsync(new ExportBacklogQuery(ExportScope.General, null, ContentTypes.All, null, null)));
var ownDue = Enumerable.Range(0, Entries).Where(n => n % Accounts == OwnAccount).Sum(n => (n % 7 != 0 ? 1 : 0) + (n % 5 == 0 ? 1 : 0));
Assert.AreEqual(copies.Due - ownDue, moved.Files);
}
/// <summary>
/// What the export fill wrote: copies by state (<paramref name="Copied"/> with the converted ones), the due files, the
/// account with its own folder, of tappa E3 the converted copies and the frames (copied and «Tolto»), and of tappa E5
/// the «Non riuscito» copies and the two destinations.
/// </summary>
private sealed record CopiesWorld(int Copied, int Removed, int Superseded, int Due, long OwnAccountId, int Converted, int Frames, int Failed, long GeneralId, long OwnId);
}