E3: correzioni della revisione di formati e fotogrammi

Le 16 osservazioni confermate della revisione, ognuna con la sua prova:

- JPEG: il controllo stima la memoria di lavoro del decodificatore
  (progressivo), così un file che non si decodifica esce «troppo
  grande» e non «illeggibile».
- Un EXIF che non si tiene lascia un EXIF minimo con l'orientamento,
  perché la foto convertita non esca girata.
- Fotogrammi: istanti in millisecondi interi; la copia trova l'indice
  del nome dall'istante, non dall'ordine delle righe.
- Video di durata sconosciuta misurati prima di registrare: contano
  nei limiti di 500 per richiesta e 5000 per video.
- Rimuxaggio: la durata del segmento di elst passa nell'MP4, la fine
  tagliata resta nascosta (anche nei fotogrammi).
- H.264: il punto di recupero vale come IDR solo con exact_match_flag.
- MP3 in MP4: objectTypeIndication 0x69 fino a 24 kHz, 0x6B oltre.
- Conversione della libreria: il lavoro toglie le righe di un formato
  spento o cambiato; spegnere toglie anche i «Non riuscito»; «Riprova»
  solo i formati di adesso; pausa per spazio prima di rileggere
  l'originale.
- «Anche i N» conta e mette in coda solo il tipo che si cambia; le
  impostazioni dell'esportazione si salvano una per volta.
- Eliminazione e «Tieni il più grande» scelgono i convertiti nella
  stessa transazione: nessun convertito orfano.
- Un file arrivato tardi in un elemento vecchio mette in coda solo sé
  (file nuovo = salvato da quando il formato è scelto).
- Zip dei fotogrammi a pezzi di 64 KB: un browser lento che legge non
  si interrompe, uno fermo sì.

Decisioni in docs/decisioni.md (28/11), §4.10 della specifica precisato.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-28 13:30:33 +01:00
1 parent eb79b05fda
commit 958cb71cd6
38 files changed
+1276 -222

No files matched your search

+46 -16
View File
@@ -150,6 +150,28 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
public Task MarkDeletedAsync(long entryId, DateTimeOffset at, CancellationToken ct = default) => MarkDeletedAsync(entryId, at, [], ct);
/// <summary>
/// «Eliminato» inside the caller's transaction: the entry, its files without path, and the conversions for the
/// library of its files (tappa E3) with nothing left to convert or retry (Pending, Failed) go.
/// </summary>
private static void MarkDeleted(WriteContext w, long entryId, DateTimeOffset at)
{
var rows = w.Command("UPDATE entry SET state = 'Deleted', deleted_at = @at WHERE id = @id")
.With("@at", Sql.Time(at)).With("@id", entryId).ExecuteNonQuery();
if (rows == 0)
{
throw new KeyNotFoundException($"Elemento {entryId} non trovato.");
}
w.Command("""
UPDATE media SET state = 'Deleted', relative_path = NULL, has_thumbnail = 0, phash = NULL, source_url = NULL, cover_url = NULL
WHERE entry_id = @id
""").With("@id", entryId).ExecuteNonQuery();
w.Command("""
DELETE FROM media_conversion WHERE state IN ('Pending', 'Failed') AND media_id IN (SELECT id FROM media WHERE entry_id = @id)
""").With("@id", entryId).ExecuteNonQuery();
}
public Task MarkDeletedAsync(long entryId, DateTimeOffset at, IReadOnlyCollection<long> removedConversionIds, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(removedConversionIds);
@@ -157,23 +179,9 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
return db.WriteAsync(
w =>
{
var rows = w.Command("UPDATE entry SET state = 'Deleted', deleted_at = @at WHERE id = @id")
.With("@at", Sql.Time(at)).With("@id", entryId).ExecuteNonQuery();
if (rows == 0)
{
throw new KeyNotFoundException($"Elemento {entryId} non trovato.");
}
MarkDeleted(w, entryId, at);
w.Command("""
UPDATE media SET state = 'Deleted', relative_path = NULL, has_thumbnail = 0, phash = NULL, source_url = NULL, cover_url = NULL
WHERE entry_id = @id
""").With("@id", entryId).ExecuteNonQuery();
// The conversions for the library of its files (tappa E3): nothing left to convert or retry; the
// converted files that go (or are gone) are «Tolto», the others stay as they are.
w.Command("""
DELETE FROM media_conversion WHERE state IN ('Pending', 'Failed') AND media_id IN (SELECT id FROM media WHERE entry_id = @id)
""").With("@id", entryId).ExecuteNonQuery();
// The converted files that go (or are gone) are «Tolto», the others stay as they are.
if (removed.Count > 0)
{
var own = new HashSet<long>();
@@ -192,6 +200,28 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
ct);
}
public Task<IReadOnlyList<MediaConversion>> MarkDeletedWithConversionsAsync(long entryId, DateTimeOffset at, CancellationToken ct = default) =>
db.WriteAsync<IReadOnlyList<MediaConversion>>(
w =>
{
var withFiles = new List<MediaConversion>();
using (var r = w.Command($"""
SELECT {MediaConversionStore.JoinedColumnList} FROM media_conversion mc JOIN media m ON m.id = mc.media_id
WHERE m.entry_id = @id AND mc.state IN ('Converted', 'Superseded') ORDER BY mc.media_id, mc.id
""").With("@id", entryId).ExecuteReader())
{
while (r.Read())
{
withFiles.Add(MediaConversionStore.ReadRow(r));
}
}
MarkDeleted(w, entryId, at);
MediaConversionStore.MarkRemoved(w, withFiles.Select(c => c.Id).ToList(), at);
return withFiles;
},
ct);
public Task RemoveAsync(long entryId, CancellationToken ct = default) =>
db.WriteAsync(
w =>
@@ -115,14 +115,18 @@ internal sealed partial class MediaConversionStore
return changed;
}
public Task<int> ForgetDeletedMediaAsync(long mediaId, DateTimeOffset at, CancellationToken ct = default) =>
db.WriteAsync(
public Task<IReadOnlyList<MediaConversion>> ForgetDeletedMediaAsync(long mediaId, DateTimeOffset at, CancellationToken ct = default) =>
db.WriteAsync<IReadOnlyList<MediaConversion>>(
w =>
{
w.Command("UPDATE media SET state = 'Deleted' WHERE id = @m").With("@m", mediaId).ExecuteNonQuery();
w.Command("DELETE FROM media_conversion WHERE media_id = @m AND state IN ('Pending', 'Failed')").With("@m", mediaId).ExecuteNonQuery();
return w.Command("""
UPDATE media_conversion SET state = 'Removed', state_changed_at = @at WHERE media_id = @m AND state IN ('Converted', 'Superseded')
""").With("@m", mediaId).With("@at", Sql.Time(at)).ExecuteNonQuery();
var removed = ReadAll(w.Command($"""
SELECT {JoinedColumns} FROM media_conversion mc JOIN media m ON m.id = mc.media_id
WHERE mc.media_id = @m AND mc.state IN ('Converted', 'Superseded') ORDER BY mc.id
""").With("@m", mediaId));
MarkRemoved(w, removed.Select(c => c.Id).ToList(), at);
return removed;
},
ct);
@@ -183,9 +187,12 @@ internal sealed partial class MediaConversionStore
ct);
}
public Task<int> DeletePendingAsync(ExportFormat format, CancellationToken ct = default) =>
public Task<int> DeleteQueueAsync(ExportFormat format, CancellationToken ct = default) =>
db.WriteAsync(
w => w.Command("DELETE FROM media_conversion WHERE state = 'Pending' AND format = @f").With("@f", Sql.Enum(format)).ExecuteNonQuery(),
w => w.Command($"""
DELETE FROM media_conversion
WHERE format = @f AND (state = 'Pending' OR (state = 'Failed' AND (last_error IS NULL OR NOT ({AsIsCondition}))))
""").With("@f", Sql.Enum(format)).ExecuteNonQuery(),
ct);
public Task<bool> DeletePendingRowAsync(long id, CancellationToken ct = default) =>
@@ -454,11 +461,25 @@ internal sealed partial class MediaConversionStore
return MediaConversionCommitOutcome.Upserted;
}
public Task<int> ResetFailedAsync(DateTimeOffset at, CancellationToken ct = default) =>
db.WriteAsync(
w => w.Command($"""
UPDATE media_conversion SET state = 'Pending', last_error = NULL, state_changed_at = @at
WHERE state = 'Failed' AND (last_error IS NULL OR NOT ({AsIsCondition}))
""").With("@at", Sql.Time(at)).ExecuteNonQuery(),
public Task<int> ResetFailedAsync(IReadOnlyCollection<ExportFormat> formats, DateTimeOffset at, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(formats);
if (formats.Count == 0)
{
return Task.FromResult(0);
}
return db.WriteAsync(
w =>
{
using var command = w.Connection.Command(string.Empty, w.Transaction);
var list = command.AddList("f", formats.Distinct().Select(f => Sql.Enum(f)).ToList());
command.CommandText = $"""
UPDATE media_conversion SET state = 'Pending', last_error = NULL, state_changed_at = @at
WHERE state = 'Failed' AND format IN ({list}) AND (last_error IS NULL OR NOT ({AsIsCondition}))
""";
return command.With("@at", Sql.Time(at)).ExecuteNonQuery();
},
ct);
}
}