E3: conversione della libreria in sottofondo con righe sempre vere
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>
This commit is contained in:
1 parent
b746aff45d
commit
724c5bda6f
25 files changed
+2621
-38
No files matched your search
@@ -148,8 +148,13 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
|
||||
public Task<EntryState> RecomputeStateAsync(long entryId, CancellationToken ct = default) =>
|
||||
db.WriteAsync(w => RecomputeState(w, entryId), ct);
|
||||
|
||||
public Task MarkDeletedAsync(long entryId, DateTimeOffset at, CancellationToken ct = default) =>
|
||||
db.WriteAsync(
|
||||
public Task MarkDeletedAsync(long entryId, DateTimeOffset at, CancellationToken ct = default) => MarkDeletedAsync(entryId, at, [], ct);
|
||||
|
||||
public Task MarkDeletedAsync(long entryId, DateTimeOffset at, IReadOnlyCollection<long> removedConversionIds, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(removedConversionIds);
|
||||
var removed = removedConversionIds.Distinct().ToList();
|
||||
return db.WriteAsync(
|
||||
w =>
|
||||
{
|
||||
var rows = w.Command("UPDATE entry SET state = 'Deleted', deleted_at = @at WHERE id = @id")
|
||||
@@ -163,11 +168,69 @@ internal sealed class EntryStore(FebeDatabase db) : IEntryStore
|
||||
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();
|
||||
if (removed.Count > 0)
|
||||
{
|
||||
var own = new HashSet<long>();
|
||||
using (var r = w.Command("SELECT mc.id FROM media_conversion mc JOIN media m ON m.id = mc.media_id WHERE m.entry_id = @id")
|
||||
.With("@id", entryId).ExecuteReader())
|
||||
{
|
||||
while (r.Read())
|
||||
{
|
||||
own.Add(r.GetInt64(0));
|
||||
}
|
||||
}
|
||||
|
||||
MediaConversionStore.MarkRemoved(w, removed.Where(own.Contains).ToList(), at);
|
||||
}
|
||||
},
|
||||
ct);
|
||||
}
|
||||
|
||||
public Task RemoveAsync(long entryId, CancellationToken ct = default) =>
|
||||
db.WriteAsync(
|
||||
w =>
|
||||
{
|
||||
MediaConversionStore.DeleteRowsWithoutFile(w, entryId);
|
||||
try
|
||||
{
|
||||
w.Command("DELETE FROM entry WHERE id = @id").With("@id", entryId).ExecuteNonQuery();
|
||||
}
|
||||
catch (SqliteException ex) when (ex.IsConstraintViolation())
|
||||
{
|
||||
// ON DELETE RESTRICT of media_conversion: a converted file of the library would lose its record.
|
||||
throw new InvalidOperationException(
|
||||
"L'elemento ha file convertiti nella libreria: eliminalo con «Elimina dalla libreria», che toglie anche quelli.", ex);
|
||||
}
|
||||
},
|
||||
ct);
|
||||
|
||||
public Task RemoveAsync(long entryId, CancellationToken ct = default) =>
|
||||
db.WriteAsync(w => w.Command("DELETE FROM entry WHERE id = @id").With("@id", entryId).ExecuteNonQuery(), ct);
|
||||
public Task<IReadOnlyList<MediaConversion>> RemoveWithConversionsAsync(long entryId, CancellationToken ct = default) =>
|
||||
db.WriteAsync<IReadOnlyList<MediaConversion>>(
|
||||
w =>
|
||||
{
|
||||
var list = 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 ORDER BY mc.media_id, mc.id
|
||||
""").With("@id", entryId).ExecuteReader())
|
||||
{
|
||||
while (r.Read())
|
||||
{
|
||||
list.Add(MediaConversionStore.ReadRow(r));
|
||||
}
|
||||
}
|
||||
|
||||
w.Command("DELETE FROM media_conversion WHERE media_id IN (SELECT id FROM media WHERE entry_id = @id)").With("@id", entryId).ExecuteNonQuery();
|
||||
w.Command("DELETE FROM entry WHERE id = @id").With("@id", entryId).ExecuteNonQuery();
|
||||
return list;
|
||||
},
|
||||
ct);
|
||||
|
||||
public Task<IReadOnlyList<Entry>> ListByAccountAsync(long accountId, EntryListOptions? options = null, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user