D1, correzioni della revisione: conteggi della Libreria più rapidi, frecce che seguono le tessere, Dashboard nei testi

- /api/library/days in «Tutte le foto» faceva due volte il passaggio su tutta la tabella media
  a ogni aggiornamento del mosaico: il totale dei file è ora la somma dei giorni
  (CountLibraryFilesAsync tolto).
- I totali e i conteggi per giorno di «Foto» e «Video» su tutta la libreria non pagano più un
  EXISTS per post (1,3-1,6 s): elenco degli elementi con file di quel tipo su un indice di
  copertura, 86-141 ms su 200.000 elementi; nuove misure con limite 600 ms in LibraryScaleTests.
- La quota di chi aspetta non è un minimo per tipo: corretti commento e decisioni, prova con un
  arretrato più vecchio di un altro tipo.
- Visualizzatore in «Tutte le foto»: le frecce saltano i file che non sono tessere (foto sotto
  «Video» e simili) e l'intestazione non dà il numero di un altro file; la voce già scelta
  dell'interruttore non ridisegna il mosaico. Prova d'interfaccia nuova (solo CI).
- «Ricetta sospesa» dice di riattivarla dalla Dashboard, non da Attività; commenti aggiornati.
- Nomi accessibili distinti nella scheda account, variabile in inglese in download-order.js,
  icona activity tolta perché nessuna pagina la usa.
- Schermate 06, 11 e 14 rifatte con /dashboard e nuova 01-libreria-tutte-le-foto, confrontate
  con i mockup in docs/schermate/differenze.md (con quattro difetti visivi ancora da sistemare).
- LEGGIMI del web (mode, cursore, files, moduli riusabili) e guida della Libreria (la scelta del
  mosaico resta nel browser, a differenza del tema).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 17:27:33 +01:00
1 parent 30e159cbd4
commit 58ff4e48b3
44 files changed
+261 -118

No files matched your search

+19 -33
View File
@@ -323,7 +323,7 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
c =>
{
var command = c.Command(string.Empty);
var where = BuildWhere(c, command, filter);
var where = BuildWhere(c, command, filter, aggregate: true);
command.CommandText = $"SELECT COUNT(*), COUNT(DISTINCT e.account_id) FROM entry e WHERE {where}";
using var r = command.ExecuteReader();
r.Read();
@@ -332,34 +332,6 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
ct);
}
public Task<int> CountLibraryFilesAsync(LibraryFilter filter, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(filter);
return db.ReadAsync(
c =>
{
var command = c.Command(string.Empty);
var where = BuildWhere(c, command, EntriesOfFiles(filter));
var counts = FileCounts(c, filter);
if (counts is null)
{
command.CommandText = $"SELECT COALESCE(SUM({FilesOfEntry(filter)}), 0) FROM entry e WHERE {where}";
return (int)command.ScalarInt64();
}
command.CommandText = $"SELECT e.id FROM entry e WHERE {where}";
var total = 0;
using var r = command.ExecuteReader();
while (r.Read())
{
total += counts.GetValueOrDefault(r.GetInt64(0));
}
return total;
},
ct);
}
public Task<IReadOnlyList<DayCount>> CountLibraryByDayAsync(LibraryFilter filter, TimeZoneInfo zone, MosaicMode mode = MosaicMode.Grouped, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(filter);
@@ -371,7 +343,7 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
// in SQL, no sort, and the day bounds are computed once per day rather than once per entry.
var command = c.Command(string.Empty);
var files = mode == MosaicMode.Files;
var where = BuildWhere(c, command, files ? EntriesOfFiles(filter) : filter);
var where = BuildWhere(c, command, files ? EntriesOfFiles(filter) : filter, aggregate: true);
var counts = files ? FileCounts(c, filter) : null;
var perEntry = files && counts is null;
command.CommandText = !files
@@ -758,8 +730,22 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
}
/// <summary>The WHERE clause of a library filter on <c>entry e</c>; parameters are added to <paramref name="command"/>.</summary>
internal static string BuildWhere(SqliteConnection c, SqliteCommand command, LibraryFilter filter)
/// <param name="aggregate">
/// The clause is for a count over every entry of the filter (totals, day counts) rather than for a window. «Foto» and
/// «Video» then test the key of each post, on a covering index, against one list of the entries that have such
/// files, read once from ix_media_entry_files (under two tenths of a second over 200,000 entries), instead of an
/// EXISTS per post (over a second: each post needs its table row). A window keeps the EXISTS: it stops after a few
/// hundred posts in index order.
/// With a filter on accounts the posts are few and the EXISTS is the cheaper of the two.
/// </param>
internal static string BuildWhere(SqliteConnection c, SqliteCommand command, LibraryFilter filter, bool aggregate = false)
{
var byList = aggregate && filter.AccountIds is not { Count: > 0 };
// The unary + on kind and key keeps SQLite on a covering index of entry (kind, state and account in the index):
// looking up each entry of the list by key would read its table row, 0.85 s for «Foto» over 200,000 entries.
string FilesOfKind(string kind) => byList
? $"+e.kind = 'Post' AND +e.id IN (SELECT mk.entry_id FROM media mk WHERE mk.kind = '{kind}')"
: $"e.kind = 'Post' AND EXISTS (SELECT 1 FROM media mk WHERE mk.entry_id = e.id AND mk.kind = '{kind}')";
var parts = new List<string>();
var states = filter.States is { Count: > 0 } s ? s : EntryStateRules.Visible;
// The unary + keeps SQLite from using the state and kind indexes for these broad terms: the keyset scan of the
@@ -772,8 +758,8 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
// Like «Tutto», a broad term: on the kind index every post would need its table row for the state (most of
// the library); the publication index already holds kind and state.
LibraryKindFilter.Posts => "+e.kind = 'Post'",
LibraryKindFilter.Photos => "e.kind = 'Post' AND EXISTS (SELECT 1 FROM media mk WHERE mk.entry_id = e.id AND mk.kind = 'Photo')",
LibraryKindFilter.Videos => "e.kind = 'Post' AND EXISTS (SELECT 1 FROM media mk WHERE mk.entry_id = e.id AND mk.kind = 'Video')",
LibraryKindFilter.Photos => FilesOfKind("Photo"),
LibraryKindFilter.Videos => FilesOfKind("Video"),
LibraryKindFilter.Stories => "e.kind = 'Story'",
LibraryKindFilter.Highlights => "(e.kind = 'Highlight' OR EXISTS (SELECT 1 FROM highlight_entry he WHERE he.entry_id = e.id))",
LibraryKindFilter.Tagged => "e.kind = 'Tagged'",