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);
@@ -65,7 +65,7 @@ public sealed class InstagramReaderTests
{
Vocabulary.Content.Id, Vocabulary.Content.Code, Vocabulary.Content.TakenAt, Vocabulary.Content.Caption, Vocabulary.Content.Images,
Vocabulary.Content.Videos, Vocabulary.Content.Children, Vocabulary.Content.ChildCount, Vocabulary.Content.Owner, Vocabulary.Content.Pinned,
Vocabulary.Content.ExpiresAt, Vocabulary.Content.Duration, Vocabulary.Version.Url, Vocabulary.Version.Width, Vocabulary.Version.Height,
Vocabulary.Content.ExpiresAt, Vocabulary.Content.Duration, Vocabulary.Content.ProductType, Vocabulary.Version.Url, Vocabulary.Version.Width, Vocabulary.Version.Height,
Vocabulary.Version.HasAudio, Vocabulary.Profile.Id, Vocabulary.Profile.Username, Vocabulary.Profile.DisplayName, Vocabulary.Profile.IsPrivate,
Vocabulary.Profile.IsFollowed, Vocabulary.Profile.PostCount, Vocabulary.Profile.Picture, Vocabulary.Profile.LatestStoryAt,
Vocabulary.Highlight.Id, Vocabulary.Highlight.Title, Vocabulary.Highlight.Owner, Vocabulary.Highlight.Items, Vocabulary.Highlight.Cover,
@@ -82,6 +82,14 @@ public sealed class InstagramReaderTests
{
Assert.IsTrue(names.Contains(key), $"«{key}» non compare in nessun campione ripulito di Instagram.");
}
// The values that mean «reel» are values of the samples too (rule 9).
var samples = string.Concat(Directory.EnumerateFiles(Path.Combine(AppContext.BaseDirectory, "campioni", "instagram"), "*.json").Select(File.ReadAllText));
Assert.IsNotEmpty(Vocabulary.Content.ReelTypes);
foreach (var value in Vocabulary.Content.ReelTypes)
{
Assert.Contains($"\"product_type\": \"{value}\"", samples, $"«{value}» non compare come product_type in nessun campione ripulito di Instagram.");
}
}
[TestMethod]
@@ -230,6 +238,8 @@ public sealed class InstagramReaderTests
Assert.AreEqual(MediaKind.Video, reel.Kind);
Assert.AreEqual((720, 1280), (reel.Best.Width, reel.Best.Height));
Assert.IsNotNull(reel.Cover);
Assert.IsTrue(result.Contents[0].IsReel, "product_type «clips»: a reel for «Cosa scaricare prima».");
Assert.IsFalse(result.Contents[1].IsReel, "product_type «carousel_container»: a series.");
var series = result.Contents[1].Files;
Assert.AreEqual(6, series.Count, "carousel_media: one file for each child.");
@@ -120,7 +120,10 @@ public sealed class RequestRecipeTests
CollectionAssert.AreEqual(new[] { "taggati", "reel" }, bed.Scripted!.Sent.Select(s => s.Operation).ToArray());
CollectionAssert.AreEqual(new[] { ActionKind.BackfillPage, ActionKind.BackfillPage }, bed.Governor.Requests.Select(r => r.Kind).ToArray());
Assert.AreEqual(3, (await bed.Db.Entries.ListByAccountAsync(marta.Id, new EntryListOptions { Kind = EntryKind.Tagged, Limit = 100 })).Count);
Assert.AreEqual(6, (await bed.Db.Entries.ListByAccountAsync(reels.Id, new EntryListOptions { Kind = EntryKind.Post, Limit = 100 })).Count);
var reelPosts = await bed.Db.Entries.ListByAccountAsync(reels.Id, new EntryListOptions { Kind = EntryKind.Post, Limit = 100 });
Assert.AreEqual(6, reelPosts.Count);
Assert.IsTrue(reelPosts.All(e => e.IsReel), "what the Reel tab gives is a reel («Cosa scaricare prima», spec §7.2)");
Assert.IsTrue((await bed.Db.Entries.ListByAccountAsync(marta.Id, new EntryListOptions { Kind = EntryKind.Tagged, Limit = 100 })).All(e => !e.IsReel), "a tagged post is never a reel");
Assert.IsNotNull(await bed.Db.Settings.GetAsync($"raccolta.taggati.{Id(marta)}.completo"));
Assert.IsNotNull(await bed.Db.Settings.GetAsync($"raccolta.reel.{Id(reels)}.completo"));
}