La libreria può ora tenere accanto a ogni originale una copia nel formato scelto, preparata in sottofondo senza mai sostituire o cancellare l'originale. - LongWorkGate ha un permesso di sottofondo che il lavoro in primo piano (importazione, copie, ricostruzione) interrompe; il salvataggio in corso si aspetta al più CommitWait. - La coda e il lavoratore: nuovi file accodati all'arrivo, quelli già in libreria solo su richiesta, pausa, nuovo tentativo, attesa durante una sessione del motore o con poco spazio, nomi liberi e adozione di un file identico già presente. - Le righe di media_conversion restano vere in ogni via: eliminazione (Ricorda e Consenti il ritorno, con RemoveWithConversionsAsync per il vincolo RESTRICT), perdente del ripasso dei doppioni, file cambiato (superate e riaccodate), ricostruzione (conta e riconosce i convertiti, accoda solo Pending), importazione (una copia convertita o un fotogramma non rientra come file nuovo). - FebeApp avvia il lavoratore con InBackground; la demo mai. _febe.jsonl non cambia. La prova RecordsCannotBeDeletedFromUnderTheirCopies usa ora una riga Converted: RemoveAsync toglie da sé le righe senza file, e il vincolo si verifica sia in SQL sia attraverso il magazzino. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
7.4 KiB
C#
115 lines
7.4 KiB
C#
using Febe.Core.Domain;
|
|
|
|
namespace Febe.Core.Storage;
|
|
|
|
/// <summary>Entries (spec §4.3, §8.3 <c>entry</c>) and the library queries of the interface (spec §4.6).</summary>
|
|
public interface IEntryStore
|
|
{
|
|
Task<Entry?> GetAsync(long entryId, CancellationToken ct = default);
|
|
|
|
Task<EntryWithMedia?> GetWithMediaAsync(long entryId, CancellationToken ct = default);
|
|
|
|
/// <summary>The entry with this identity, in any state (deleted included).</summary>
|
|
Task<Entry?> FindAsync(long accountId, EntryKind kind, string instagramId, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// «Is this Instagram identifier known?» for (account, kind), in any state — deleted entries count as known so
|
|
/// they are never downloaded again (spec §4.6).
|
|
/// </summary>
|
|
Task<bool> IsKnownAsync(long accountId, EntryKind kind, string instagramId, CancellationToken ct = default);
|
|
|
|
/// <summary>Which of these identifiers are already known for (account, kind), in any state. For readers: one query per page.</summary>
|
|
Task<IReadOnlySet<string>> GetKnownInstagramIdsAsync(long accountId, EntryKind kind, IReadOnlyCollection<string> instagramIds, CancellationToken ct = default);
|
|
|
|
/// <summary>Entries of an account with this Instagram identifier, any kind and state (e.g. a story that entered a highlight).</summary>
|
|
Task<IReadOnlyList<Entry>> FindByInstagramIdAsync(long accountId, string instagramId, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// An entry of (account, kind) published within <paramref name="tolerance"/> of <paramref name="publishedAt"/>:
|
|
/// recognizes imported entries that have no Instagram identifier (spec §9.5, two seconds).
|
|
/// </summary>
|
|
Task<Entry?> FindByPublicationTimeAsync(long accountId, EntryKind kind, DateTimeOffset publishedAt, TimeSpan tolerance, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Adds an entry with its files in one transaction. Idempotent on (account, kind, Instagram identifier): when the
|
|
/// entry is already known, nothing changes and the stored entry is returned with <c>Created = false</c>.
|
|
/// Positions of the files must be distinct.
|
|
/// </summary>
|
|
Task<AddEntryResult> AddAsync(Entry entry, IReadOnlyList<Media> media, CancellationToken ct = default);
|
|
|
|
/// <summary>Adds many entries in one transaction (import, rebuild). Same semantics as <see cref="AddAsync"/>.</summary>
|
|
Task<IReadOnlyList<AddEntryResult>> AddManyAsync(IReadOnlyList<NewEntry> entries, CancellationToken ct = default);
|
|
|
|
/// <summary>Replaces the mutable fields of an entry (Instagram identifier, code, caption, author, state, dates).</summary>
|
|
Task UpdateAsync(Entry entry, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Marks a post as a reel (spec §7.2, «Cosa scaricare prima»), writing only that flag; other kinds are left as they are.
|
|
/// A reel never goes back to a plain post: <see cref="UpdateAsync"/> keeps the flag once set.
|
|
/// </summary>
|
|
Task MarkReelAsync(long entryId, CancellationToken ct = default);
|
|
|
|
Task SetStateAsync(long entryId, EntryState state, CancellationToken ct = default);
|
|
|
|
/// <summary>Recomputes the state of an entry from its files (<see cref="EntryStateRules.FromMedia"/>).</summary>
|
|
Task<EntryState> RecomputeStateAsync(long entryId, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// «Eliminato»: the entry stays without files so it is not downloaded again (spec §4.6). Its files become
|
|
/// <see cref="MediaState.Deleted"/> and lose their path and perceptual hash; SHA-256 and size are kept. Deleting files on disk is the caller's job.
|
|
/// </summary>
|
|
Task MarkDeletedAsync(long entryId, DateTimeOffset at, CancellationToken ct = default) => MarkDeletedAsync(entryId, at, [], ct);
|
|
|
|
/// <summary>
|
|
/// As <see cref="MarkDeletedAsync(long, DateTimeOffset, CancellationToken)"/>, and in the same transaction the
|
|
/// conversions for the library of its files: the queue and the failures (Pending, Failed) go, and the rows of
|
|
/// <paramref name="removedConversionIds"/> (whose converted file goes or is gone) become «Tolto». Other converted rows stay.
|
|
/// </summary>
|
|
Task MarkDeletedAsync(long entryId, DateTimeOffset at, IReadOnlyCollection<long> removedConversionIds, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// «Eliminalo e lascia che torni»: removes the record (files records and highlight links by cascade). Conversions
|
|
/// without a file left (Pending, Failed, Removed) go with it; a Converted or Superseded one makes it fail with
|
|
/// <see cref="InvalidOperationException"/> (its file would be forgotten): use <see cref="RemoveWithConversionsAsync"/>.
|
|
/// </summary>
|
|
Task RemoveAsync(long entryId, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// «Eliminalo e lascia che torni» from «Elimina dalla libreria»: removes the record and every conversion of its files
|
|
/// in one transaction, and returns the conversions removed (their converted files are the caller's to delete).
|
|
/// </summary>
|
|
Task<IReadOnlyList<MediaConversion>> RemoveWithConversionsAsync(long entryId, CancellationToken ct = default);
|
|
|
|
/// <summary>Entries of an account ordered by publication time, newest first (account tabs, collection pipeline).</summary>
|
|
Task<IReadOnlyList<Entry>> ListByAccountAsync(long accountId, EntryListOptions? options = null, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// What a recipe saved (spec §7.9, thumbnails of the history of the Dashboard): the entries Febe downloaded (never
|
|
/// the imported ones) discovered in [from, to], of the account or, with null, of every account (the Giro dei
|
|
/// seguiti), newest first, at most <paramref name="limit"/>, with how many there are in all.
|
|
/// </summary>
|
|
Task<ArrivedEntries> ListDiscoveredAsync(long? accountId, DateTimeOffset from, DateTimeOffset to, int limit, CancellationToken ct = default);
|
|
|
|
/// <summary>Entries of (account, kind) discovered in [from, to): per-account daily backfill limit.</summary>
|
|
Task<int> CountDiscoveredAsync(long accountId, EntryKind kind, DateTimeOffset from, DateTimeOffset to, CancellationToken ct = default);
|
|
|
|
/// <summary>A window of the library mosaic with keyset paging: stays fast over 200,000 entries.</summary>
|
|
Task<LibraryPage> QueryLibraryAsync(LibraryQuery query, CancellationToken ct = default);
|
|
|
|
Task<LibraryTotals> GetLibraryTotalsAsync(LibraryFilter filter, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Entries (or, with <see cref="MosaicMode.Files"/>, files) per local calendar day in Alberto's zone, newest day
|
|
/// first. A day without files is left out in that mode. In that mode the files are those in the library
|
|
/// (downloaded or imported), the tiles of «Tutte le foto», with «Foto» and «Video» only the files of that kind; their
|
|
/// total is the sum of the days (one pass over the files, not a second count).
|
|
/// </summary>
|
|
Task<IReadOnlyList<DayCount>> CountLibraryByDayAsync(LibraryFilter filter, TimeZoneInfo zone, MosaicMode mode = MosaicMode.Grouped, CancellationToken ct = default);
|
|
|
|
/// <summary>Tiles for given entries, in the given order (e.g. the items of a highlight collection).</summary>
|
|
Task<IReadOnlyList<LibraryTile>> GetTilesAsync(IReadOnlyList<long> entryIds, CancellationToken ct = default);
|
|
}
|
|
|
|
/// <summary>Entries saved by a recipe: the first ones, newest first, and how many in all.</summary>
|
|
public sealed record ArrivedEntries(IReadOnlyList<long> EntryIds, int Total);
|