D1, seconda parte: «Cosa scaricare prima» anche per account, reel distinti e quota per chi aspetta

L'ordine dei tipi (storie, evidenza, post, reel, taggati) ora vale anche per il singolo account:
nella scheda account → Impostazioni si sceglie «Come le impostazioni generali» o un ordine suo,
con lo stesso elenco da trascinare (o Su/Giù da tastiera) di Limiti e comportamento, ora un
modulo solo (download-order.js). Il motore pesa le visite con l'ordine dell'account, la coda dei
file mette ogni file al posto del suo tipo nell'ordine del suo account, stabile dentro il tipo
(scadenza, scoperta, elemento, posizione).

Perché nessun tipo resti fermo per sempre quando il tetto dei dati finisce prima della coda, un
posto su otto di ogni giro della coda va al file che aspetta da più tempo, di qualunque tipo.

I reel non si inventano (regola 9): un post è reel se viene dalla scheda Reel o se la risposta
ha product_type «clips», valore visto nei campioni ripuliti. Il segno si scrive da solo e non si
toglie mai, così una copia vecchia non sposta di nuovo i file in coda.

Migrazione 0002_ordine_scaricamento (account.download_order, entry.is_reel): prende il primo
numero dopo quelle unite, E1 userà il successivo. Prove su motore (seme fisso), coda, lettori,
ricette e API; dimostrazione con un account che ha l'ordine suo; guida e decisioni aggiornate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 15:25:34 +01:00
1 parent d6c0ef851d
commit 0547c747c5
40 files changed
+775 -158

No files matched your search

@@ -406,6 +406,44 @@ public sealed class DownloadQueueTests
Assert.AreEqual(1, cdp.Sent.Count(c => c.Method == "IO.close"));
}
[TestMethod]
public async Task TheFilesArriveInTheOrderOfEachAccountWithAShareForTheLongestWaiting()
{
// «Cosa scaricare prima» (spec §6.5, §7.2): the general order for one account, an order of its own for the other.
using var temp = new TempFolder("coda-ordine");
await using var library = await TestLibrary.CreateAsync(temp);
var marta = await library.Db.Accounts.AddAsync(Make.Account("marta.prova", "1001"));
var luca = await library.Db.Accounts.AddAsync(Make.Account("luca.prova", "1002") with { DownloadOrder = "taggati,post" });
await AddAsync(library.Db, marta, "s", EntryKind.Story, "https://cdn.esempio/m/storia.jpg");
await AddAsync(library.Db, marta, "p", EntryKind.Post, "https://cdn.esempio/m/post.jpg");
await AddAsync(library.Db, luca, "q", EntryKind.Post, "https://cdn.esempio/m/post-luca.jpg");
await AddAsync(library.Db, luca, "g", EntryKind.Tagged, "https://cdn.esempio/m/taggato-luca.jpg");
var asked = new List<string>();
var fetcher = new ScriptedFetcher((address, destination, ct) =>
{
lock (asked)
{
asked.Add(address!.AbsolutePath);
}
return ScriptedFetcher.PhotoByPath(address, destination, ct);
});
var orderOnly = Queue(library, temp, fetcher, options: new DownloadOptions { StagingFolder = temp.Combine("dati", "temporanei"), MaxConcurrent = 1, LongestWaitingShare = 0 });
Assert.AreEqual(4, (await orderOnly.RunOnceAsync(CancellationToken.None)).Stored);
CollectionAssert.AreEqual(new[] { "/m/storia.jpg", "/m/taggato-luca.jpg", "/m/post-luca.jpg", "/m/post.jpg" }, asked);
// With one place in two for the longest waiting, Marta's post, found first, is the second file.
asked.Clear();
var older = (await library.Db.Entries.AddAsync(Make.Entry(marta.Id, "vecchio", Make.T0.AddDays(-3)) with { DiscoveredAt = Make.T0.AddDays(-2) }, [Make.Photo() with { SourceUrl = "https://cdn.esempio/m/vecchio.jpg", SourceSeenAt = Make.T0 }])).Stored.Entry;
await AddAsync(library.Db, marta, "s2", EntryKind.Story, "https://cdn.esempio/m/storia-2.jpg");
await AddAsync(library.Db, marta, "s3", EntryKind.Story, "https://cdn.esempio/m/storia-3.jpg");
var shared = Queue(library, temp, fetcher, options: new DownloadOptions { StagingFolder = temp.Combine("dati", "temporanei"), MaxConcurrent = 1, LongestWaitingShare = 2 });
Assert.AreEqual(3, (await shared.RunOnceAsync(CancellationToken.None)).Stored);
CollectionAssert.AreEqual(new[] { "/m/storia-2.jpg", "/m/vecchio.jpg", "/m/storia-3.jpg" }, asked);
Assert.AreEqual(EntryState.Downloaded, (await library.Db.Entries.GetAsync(older.Id))!.State);
}
private static DownloadQueue Queue(TestLibrary library, TempFolder temp, IFileFetcher fetcher, SignalDetector? signals = null, DownloadOptions? options = null, IDataBudget? budget = null) =>
new(library.Db, library.Ingest, fetcher, budget ?? new FakeDataBudget(), library.Clock, new SeededRandom(1), options ?? new DownloadOptions { StagingFolder = temp.Combine("dati", "temporanei") }, signals);