M1 Dati e libreria: modello, archivi SQLite con scrittore unico, nomi dei file, scrittura sicura, miniature, impronte, _febe.jsonl, copie, eliminazione e ricostruzione

Modello del dominio e interfacce degli archivi in Febe.Core; implementazione SQLite in Febe.Data (WAL, chiavi esterne, migrazioni numerate in transazione, coda di scrittura su un solo thread); logica della libreria in Febe.Core/Library; 164 prove MSTest, compresa la ricostruzione del database da una libreria di prova e la scala a 200.000 elementi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 16:06:15 +00:00
1 parent c803bd98b5
commit 3aeaa17da7
69 files changed
+12472

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
using Febe.Core.Domain;
namespace Febe.Core.Storage;
/// <summary>Accounts (spec §4.2, §8.3 <c>account</c>).</summary>
public interface IAccountStore
{
Task<Account?> GetAsync(long accountId, CancellationToken ct = default);
/// <summary>The account with this Instagram identifier: the identity of an account.</summary>
Task<Account?> FindByInstagramIdAsync(string instagramId, CancellationToken ct = default);
/// <summary>Case-insensitive lookup by current user name.</summary>
Task<Account?> FindByUsernameAsync(string username, CancellationToken ct = default);
/// <summary>Alberto's own profile («Tu»), when known.</summary>
Task<Account?> GetMineAsync(CancellationToken ct = default);
/// <summary>All accounts, ordered by user name.</summary>
Task<IReadOnlyList<Account>> ListAsync(CancellationToken ct = default);
/// <summary>All accounts with their counts; «new» counts are entries discovered at or after <paramref name="newSince"/>.</summary>
Task<IReadOnlyList<AccountSummary>> ListSummariesAsync(DateTimeOffset newSince, CancellationToken ct = default);
Task<AccountStats> GetStatsAsync(long accountId, CancellationToken ct = default);
/// <summary>Adds an account and returns it with its key.</summary>
/// <exception cref="DuplicateRecordException">Another account has the same Instagram identifier, or is already «Tu».</exception>
Task<Account> AddAsync(Account account, CancellationToken ct = default);
/// <summary>Replaces every field of an existing account (settings screen).</summary>
Task UpdateAsync(Account account, CancellationToken ct = default);
Task SetStateAsync(long accountId, AccountState state, DateTimeOffset at, UnreachableReason? reason = null, CancellationToken ct = default);
/// <summary>Updates last and next check times. Null values leave the stored value unchanged.</summary>
Task UpdateChecksAsync(long accountId, AccountCheckTimes times, CancellationToken ct = default);
/// <summary>Stores the backfill resume point; <paramref name="completedAt"/> marks the backfill as finished.</summary>
Task SetBackfillAsync(long accountId, string? cursor, DateTimeOffset? completedAt, CancellationToken ct = default);
/// <summary>
/// Records a rename seen in the data (spec §4.2): updates the user name, keeps the folder (a default folder is
/// pinned to the old name) and raises the «Renamed» notice.
/// </summary>
Task RenameAsync(long accountId, string newUsername, DateTimeOffset at, CancellationToken ct = default);
/// <summary>Adds notices (e.g. unrecognized format) to an account.</summary>
Task AddNoticesAsync(long accountId, AccountNotices notices, DateTimeOffset at, CancellationToken ct = default);
/// <summary>Clears notices once Alberto has seen them.</summary>
Task ClearNoticesAsync(long accountId, AccountNotices notices, CancellationToken ct = default);
/// <summary>
/// Removes the account record and, by cascade, its entries, files records and highlights. Files on disk are not
/// touched: removing an account with its files is a library operation, and the default is to keep them and make
/// the account «Solo archivio» (spec §4.2).
/// </summary>
Task DeleteAsync(long accountId, CancellationToken ct = default);
}
/// <summary>Check times of an account; null values are left unchanged.</summary>
public sealed record AccountCheckTimes
{
public DateTimeOffset? LastProfileCheckAt { get; init; }
public DateTimeOffset? NextProfileCheckAt { get; init; }
public DateTimeOffset? LastStoriesCheckAt { get; init; }
public DateTimeOffset? NextStoriesCheckAt { get; init; }
/// <summary>Profile facts read with the check (null: unchanged).</summary>
public int? PostCount { get; init; }
public bool? IsPrivate { get; init; }
public bool? IsFollowed { get; init; }
public string? DisplayName { get; init; }
}
/// <summary>A unique constraint refused a record (duplicate Instagram identifier, second «Tu», ...).</summary>
public sealed class DuplicateRecordException : Exception
{
public DuplicateRecordException()
{
}
public DuplicateRecordException(string message)
: base(message)
{
}
public DuplicateRecordException(string message, Exception innerException)
: base(message, innerException)
{
}
}