E4: filtro «Video fermi» della libreria (kind=stillvideos)
Risposta 40 di Alberto: fra i filtri «Tipo», dopo «Video», solo nella Libreria. Mostra gli elementi di ogni tipo con un video in libreria la cui ultima analisi (l'algoritmo più alto) dice «Fermo»; in «Tutte le foto» solo quei video. Un video mai analizzato non c'è: l'analisi è solo a richiesta. L'elenco degli elementi si legge una volta per istruzione dagli esiti fermi (ix_video_analysis_still) ai file (ix_media_sha256_entry), su indici coprenti; CROSS JOIN e il + unario tengono SQLite su quei piani: senza, i conteggi per elemento giravano tutti gli SHA-256 fermi a ogni elemento (107 s per un account con 10.000 video fermi). LibraryScaleTests riempie 21.000 analisi (11.000 «Fermo») e misura finestre (55-105 ms, limite 250), totali e giorni. Prove del filtro sul database e via API. L'interfaccia (la voce in library.js) è di WP6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
51150fb611
commit
78502e9c14
7 files changed
+361
-9
No files matched your search
@@ -28,6 +28,14 @@ public enum LibraryKindFilter
|
||||
|
||||
/// <summary>Posts of any media (the «Post» tab of an account).</summary>
|
||||
Posts,
|
||||
|
||||
/// <summary>
|
||||
/// «Video fermi» (tappa E4, answer 40 of Alberto, 29 November 2026; in the library only, not in the account tabs):
|
||||
/// posts, stories, highlights and tagged posts with at least one video in the library whose latest analysis
|
||||
/// (the highest algorithm in video_analysis) says «Fermo». A video never analysed is not in it: analysis is on
|
||||
/// request only. In «Tutte le foto» only those videos.
|
||||
/// </summary>
|
||||
StillVideos,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -527,6 +527,10 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
|
||||
{
|
||||
LibraryKindFilter.Photos => " AND m.kind = 'Photo'",
|
||||
LibraryKindFilter.Videos => " AND m.kind = 'Video'",
|
||||
// Over every file (bulk) SQLite goes from the still SHA-256 to their files on ix_media_sha256; for the files
|
||||
// of a few entries the unary + keeps it on the key of the entry: on the SHA-256 index each entry would walk
|
||||
// every still video (in a correlated count, 20 ms per entry with 10,000 of them).
|
||||
LibraryKindFilter.StillVideos => $" AND m.kind = 'Video' AND {(bulk ? string.Empty : "+")}m.sha256 IN ({StillShas})",
|
||||
_ => string.Empty,
|
||||
} + (filter.Copies is { } copies ? " AND " + ExportFilterSql.FileTerm(ExportFilterSql.Load(c), copies, bulk) : string.Empty);
|
||||
|
||||
@@ -562,8 +566,38 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
|
||||
/// the files already decides (a post without videos adds 0) and the EXISTS per post of the grouped filter would cost
|
||||
/// a second over 200,000 entries.
|
||||
/// </summary>
|
||||
private static LibraryFilter EntriesOfFiles(LibraryFilter filter) =>
|
||||
filter.Kind is LibraryKindFilter.Photos or LibraryKindFilter.Videos ? filter with { Kind = LibraryKindFilter.Posts } : filter;
|
||||
private static LibraryFilter EntriesOfFiles(LibraryFilter filter) => filter.Kind switch
|
||||
{
|
||||
LibraryKindFilter.Photos or LibraryKindFilter.Videos => filter with { Kind = LibraryKindFilter.Posts },
|
||||
// «Video fermi» is of every kind of entry of «Tutto»: an entry without still videos adds 0 the same way.
|
||||
LibraryKindFilter.StillVideos => filter with { Kind = LibraryKindFilter.All },
|
||||
_ => filter,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// «Video fermi»: the SHA-256 of the videos whose latest analysis (the highest algorithm, D4 of tappa E4) says
|
||||
/// «Fermo», read once on ix_video_analysis_still; an «In movimento» of a newer algorithm takes the video out. The
|
||||
/// primary key (sha256, algorithm) answers the NOT EXISTS of each.
|
||||
/// </summary>
|
||||
private const string StillShas =
|
||||
"SELECT vs.sha256 FROM video_analysis vs WHERE vs.outcome = 'Still' "
|
||||
+ "AND NOT EXISTS (SELECT 1 FROM video_analysis vn WHERE vn.sha256 = vs.sha256 AND vn.algorithm > vs.algorithm)";
|
||||
|
||||
/// <summary>
|
||||
/// «Video fermi» on <c>entry e</c>: the entries with a still video in the library, one list read once per statement,
|
||||
/// then each entry of the publication index tested by key against it. Analysis is on request, so the still videos
|
||||
/// are few and the list is short; an EXISTS per entry would walk the whole index (each entry a lookup of its files and
|
||||
/// their table rows, over a second) whenever the filter matches few entries.
|
||||
/// The list goes from the still outcomes (ix_video_analysis_still) to their files (ix_media_sha256_entry) and checks
|
||||
/// that the file is a video in the library on ix_media_entry_files, all on covering indexes: 44 ms for 10,000 still
|
||||
/// videos, 55 ms reading the table row of each file. CROSS JOIN keeps that order (started from the files, SQLite
|
||||
/// scans all of them on ix_media_state, 90 ms); the unary + on the key keeps the check on the covering index.
|
||||
/// </summary>
|
||||
private const string StillVideoEntries =
|
||||
"SELECT ms.entry_id FROM video_analysis vs CROSS JOIN media ms ON ms.sha256 = vs.sha256 WHERE vs.outcome = 'Still' "
|
||||
+ "AND NOT EXISTS (SELECT 1 FROM video_analysis vn WHERE vn.sha256 = vs.sha256 AND vn.algorithm > vs.algorithm) "
|
||||
+ "AND EXISTS (SELECT 1 FROM media mf WHERE mf.entry_id = ms.entry_id AND mf.state IN ('Downloaded', 'Imported') "
|
||||
+ "AND mf.kind = 'Video' AND +mf.id = ms.id)";
|
||||
|
||||
/// <summary>A correlated count of the files of «Tutte le foto» of the entry <c>e</c>.</summary>
|
||||
private static string FilesOfEntry(SqliteConnection c, LibraryFilter filter) =>
|
||||
@@ -884,6 +918,9 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
|
||||
LibraryKindFilter.Highlights => "(e.kind = 'Highlight' OR EXISTS (SELECT 1 FROM highlight_entry he WHERE he.entry_id = e.id))",
|
||||
LibraryKindFilter.Tagged => "e.kind = 'Tagged'",
|
||||
LibraryKindFilter.ProfilePictures => "e.kind = 'ProfilePicture'",
|
||||
// The unary + on the key, as for the list of «Foto» and «Video»: the entries stay in the order of the
|
||||
// publication index (a window stops after its first rows), each tested against the list on its key.
|
||||
LibraryKindFilter.StillVideos => $"+e.kind IN ('Post', 'Story', 'Highlight', 'Tagged') AND +e.id IN ({StillVideoEntries})",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(filter), filter.Kind, null),
|
||||
});
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ public static class ApiMapping
|
||||
|
||||
/// <summary>
|
||||
/// The library filter from the query string: <c>kind</c> (all, photos, videos, stories, highlights, tagged, posts,
|
||||
/// profile), <c>accounts</c> (comma-separated keys), <c>from</c>/<c>to</c> (local days, inclusive),
|
||||
/// profile, stillvideos), <c>accounts</c> (comma-separated keys), <c>from</c>/<c>to</c> (local days, inclusive),
|
||||
/// <c>provenance</c> (downloaded, imported), <c>q</c> (account name or caption).
|
||||
/// </summary>
|
||||
public static LibraryFilter Filter(IQueryCollection query, TimeZoneInfo zone)
|
||||
@@ -189,6 +189,7 @@ public static class ApiMapping
|
||||
"tagged" => LibraryKindFilter.Tagged,
|
||||
"posts" => LibraryKindFilter.Posts,
|
||||
"profile" => LibraryKindFilter.ProfilePictures,
|
||||
"stillvideos" => LibraryKindFilter.StillVideos,
|
||||
_ => throw new BadRequestException("Tipo di contenuto sconosciuto."),
|
||||
};
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ sono anche `day` (`aaaa-mm-gg`) e `clock` calcolati sul fuso di Febe.
|
||||
| `POST /api/browser/show`, `/api/browser/used` | «Apri il browser» (desktop), uso del browser |
|
||||
| `GET /api/eventi` | SSE: `motore` (istantanea, al massimo ogni 300 ms, comunque ogni 60 s), `libreria` (al massimo ogni 1,5 s), commento ogni 25 s |
|
||||
| `GET /api/library/days?mode=grouped\|files` | Totali (sempre elementi: `entries`, `accounts`) e giorni con conteggio e cursore (per la finestra del mosaico); con `mode=files` («Tutte le foto») i giorni contano i file presenti in libreria e `files` è la loro somma (altrimenti `null`). Un altro valore di `mode` dà 400. Stessi filtri di `/api/library` |
|
||||
| `GET /api/library?cursor=&direction=older\|newer&limit=&mode=grouped\|files` | Una finestra di tessere, con `older`/`newer` per continuare; filtri `kind`, `accounts`, `from`, `to`, `provenance`, `q`, `copies=notCopied\|copied\|removedOrSuperseded` (solo i file dovuti; un altro valore 400). Con una cartella delle copie in uso le tessere hanno `copies` (`copied`, `partly` con `copiesDone`/`copiesDue`) e `/days` ha `hasDestinations`; il visualizzatore dà le copie di ogni file (`copies`, al più 6) e `canCopy`. Con `mode=files` una tessera per file (con la sua posizione e `files`, i file dell'elemento) e il cursore è `ms.elemento.posizione` (raggruppato `ms.elemento`); un cursore malformato o `mode` sconosciuto danno 400 |
|
||||
| `GET /api/library?cursor=&direction=older\|newer&limit=&mode=grouped\|files` | Una finestra di tessere, con `older`/`newer` per continuare; filtri `kind` (con `kind=stillvideos`, «Video fermi» della tappa E4: gli elementi con un video in libreria la cui ultima analisi dice «Fermo», e con `mode=files` solo quei video), `accounts`, `from`, `to`, `provenance`, `q`, `copies=notCopied\|copied\|removedOrSuperseded` (solo i file dovuti; un altro valore 400). Con una cartella delle copie in uso le tessere hanno `copies` (`copied`, `partly` con `copiesDone`/`copiesDue`) e `/days` ha `hasDestinations`; il visualizzatore dà le copie di ogni file (`copies`, al più 6) e `canCopy`. Con `mode=files` una tessera per file (con la sua posizione e `files`, i file dell'elemento) e il cursore è `ms.elemento.posizione` (raggruppato `ms.elemento`); un cursore malformato o `mode` sconosciuto danno 400 |
|
||||
| `GET /api/library/tiles?ids=` | Tessere per chiave |
|
||||
| `GET /api/thumbnails/{chiave}`, `GET /api/media/{id}/file[?download=1]` | Miniature (immutabili) e file (con range) |
|
||||
| `GET /api/entries/{id}`, `POST /api/entries/delete`, `/export`, `/{id}/open-on-instagram`, `POST /api/media/show-in-folder` | Visualizzatore, eliminazione (`remember` o `allowReturn`), CSV (`{ ids }` per la selezione, `{ query }` per il filtro della pagina: «Esporta l'elenco» nella riga degli strumenti) |
|
||||
|
||||
Reference in new issue
Block a user