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

+47 -36
View File
@@ -3,38 +3,20 @@ using Febe.Core.Storage;
namespace Febe.Core.Engine;
/// <summary>A type of «Cosa scaricare prima» (spec §7.2): the kinds of recipes of §6.3, grouped as Alberto names them.</summary>
public enum DownloadKind
{
/// <summary>«Storie»: Storie di un account.</summary>
Stories,
/// <summary>«Evidenza»: Raccolta in evidenza.</summary>
Highlights,
/// <summary>«Post»: Controllo del profilo and Storico, profile pictures included.</summary>
Posts,
/// <summary>«Reel»: Reel.</summary>
Reels,
/// <summary>«Taggati»: Taggati.</summary>
Tagged,
}
/// <summary>
/// «Cosa scaricare prima» (spec §7.2, tappa D1): an order of the five kinds, stored in <see cref="SettingKey"/> as their
/// Italian names separated by commas. It weighs the next visit after the Giro dei seguiti (the weight of a kind is
/// <see cref="Weight"/>, multiplied by the weight of the account) and the order of the queue of the files (spec §6.5). It
/// never adds a visit, never brings one forward and never makes the order fixed: it only weighs the choices the engine
/// already makes among the work that is due and allowed.
/// «Cosa scaricare prima» (spec §7.2, tappa D1): an order of the five kinds, stored in <see cref="SettingKey"/> (general)
/// or in <see cref="Account.DownloadOrder"/> (an account's own) as their Italian names separated by commas. It weighs the
/// next visit after the Giro dei seguiti (the weight of a kind is <see cref="Weight"/>, multiplied by the weight of the
/// account) and the order of the queue of the files (spec §6.5). It never adds a visit, never brings one forward and
/// never makes the order fixed: it only weighs the choices the engine already makes among the work that is due and
/// allowed.
/// </summary>
public sealed class DownloadOrder
{
/// <summary>The general order (Impostazioni → Limiti e comportamento).</summary>
public const string SettingKey = "scaricamento.ordine";
/// <summary>The weights of the positions, first to last (spec §7.4 table, «Peso di un tipo nella scelta»).</summary>
/// <summary>The weights of the positions, first to last (spec §7.2 table, «Peso di un tipo nella scelta»).</summary>
public static readonly IReadOnlyList<double> Weights = [16, 8, 4, 2, 1];
private static readonly (DownloadKind Kind, string Name)[] Names =
@@ -60,6 +42,9 @@ public sealed class DownloadOrder
/// <summary>The Italian name of a kind, as stored and as the interface sends it.</summary>
public static string NameOf(DownloadKind kind) => Names.First(n => n.Kind == kind).Name;
/// <summary>The names of the five kinds, first to last, as the interface shows them.</summary>
public IReadOnlyList<string> ToNames() => [.. Kinds.Select(NameOf)];
/// <summary>
/// Reads a stored order. Unknown names are left out, a kind named twice counts once and the kinds missing are added
/// at the end in the default order, so any text gives the five kinds; null or empty gives <see cref="Default"/>.
@@ -93,6 +78,16 @@ public sealed class DownloadOrder
/// <summary>The stored text: the five names, comma separated.</summary>
public override string ToString() => string.Join(',', Kinds.Select(NameOf));
/// <summary>
/// The order that applies to an account: its own when it has one (spec §4.4, «Un ordine suo»), otherwise
/// <paramref name="general"/> («Come le impostazioni generali»).
/// </summary>
public static DownloadOrder For(Account? account, DownloadOrder general)
{
ArgumentNullException.ThrowIfNull(general);
return account?.DownloadOrder is { } own && !string.IsNullOrWhiteSpace(own) ? Parse(own) : general;
}
/// <summary>0 for the first kind, 4 for the last.</summary>
public int Position(DownloadKind kind)
{
@@ -125,24 +120,18 @@ public sealed class DownloadOrder
};
/// <summary>
/// The kind of a file in the queue (spec §6.5): profile pictures go with the posts; a reel counts as a post until Febe
/// keeps whether a post is a reel (spec §8.3, the flag of <c>entry</c> of D1).
/// The kind of a file in the queue (spec §6.5, §7.2): a post counts as a reel when Febe knows that it is one
/// (<see cref="Entry.IsReel"/>), otherwise as a post; profile pictures go with the posts.
/// </summary>
public static DownloadKind KindOf(EntryKind entry) => entry switch
public static DownloadKind KindOf(EntryKind entry, bool isReel = false) => entry switch
{
EntryKind.Story => DownloadKind.Stories,
EntryKind.Highlight => DownloadKind.Highlights,
EntryKind.Tagged => DownloadKind.Tagged,
EntryKind.Post when isReel => DownloadKind.Reels,
_ => DownloadKind.Posts,
};
/// <summary>The entry kinds in the order of the queue: the position of each <see cref="EntryKind"/>, first to last.</summary>
public IReadOnlyList<EntryKind> EntryKinds()
{
var all = Enum.GetValues<EntryKind>();
return [.. all.OrderBy(e => Position(KindOf(e))).ThenBy(e => Array.IndexOf(all, e))];
}
/// <summary>The general order stored in the settings.</summary>
public static async Task<DownloadOrder> LoadAsync(ISettingsStore settings, CancellationToken ct = default)
{
@@ -150,11 +139,33 @@ public sealed class DownloadOrder
return Parse(await settings.GetAsync(SettingKey, ct).ConfigureAwait(false));
}
/// <summary>Stores the general order; the default is stored as no value («come le impostazioni predefinite»).</summary>
/// <summary>Stores the general order; the default is stored as no value (the setting is absent).</summary>
public static Task SaveAsync(ISettingsStore settings, DownloadOrder order, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(settings);
ArgumentNullException.ThrowIfNull(order);
return settings.SetAsync(SettingKey, order.IsDefault ? null : order.ToString(), ct);
}
/// <summary>
/// The order of the queue of the files (spec §6.5): the general order and the own order of each account that has
/// one, read fresh so that a change counts from the next batch.
/// </summary>
public static async Task<DownloadQueueOrder> LoadQueueOrderAsync(IFebeStorage storage, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(storage);
var general = await LoadAsync(storage.Settings, ct).ConfigureAwait(false);
var own = await storage.Accounts.ListDownloadOrdersAsync(ct).ConfigureAwait(false);
var accounts = new Dictionary<long, IReadOnlyList<DownloadKind>>(own.Count);
foreach (var (accountId, text) in own)
{
var order = Parse(text);
if (!order.Kinds.SequenceEqual(general.Kinds))
{
accounts[accountId] = order.Kinds;
}
}
return new DownloadQueueOrder(general.Kinds, accounts);
}
}
+3 -2
View File
@@ -474,8 +474,9 @@ internal sealed class SessionComposer
var kind = task.Kind == EngineTaskKind.ProfileCheck && IsStoryWork(task, accounts, now)
? DownloadKind.Stories
: DownloadOrder.KindOf(task.Kind);
var kindWeight = kind is { } k ? order.Weight(k) : 1;
if (task.AccountId is { } id && accounts.TryGetValue(id, out var account))
var owner = task.AccountId is { } ownerId ? accounts.GetValueOrDefault(ownerId) : null;
var kindWeight = kind is { } k ? DownloadOrder.For(owner, order).Weight(k) : 1;
if (owner is { } account)
{
var interval = task.Kind == EngineTaskKind.AccountStories
? CheckPolicy.StoryInterval(account, window, Options.MinimumStoryChecksPerDay)