E3: formati e fotogrammi nella copia verso le cartelle esterne

La richiesta di copia porta i formati («Copia in…» per foto e video, poi
la destinazione, poi le impostazioni), i fotogrammi dei video e la «Copia
di nuovo» di una sola copia. Il piano prevede convertiti, copiati com'è e
fotogrammi; il lavoro si ricorda di fotogrammi ed identità esatta per la
ripresa.

La copia converte prima dei controlli di spazio e di FAT32, adotta un file
già presente solo se lunghezza e SHA-256 della conversione coincidono, e
prende i fotogrammi di un video in un solo passaggio, ognuno con il suo
istante esatto come identità. Un file copiato in qualunque forma che non
sia un fotogramma è «già copiato»; un fotogramma non rende mai copiato il
file (nuovo segno FrameOnly). Le note sono un elenco di codici, con i testi
italiani nuovi e il rapporto che mostra i file copiati con una nota.

Le prove dell'archivio e dei piani delle query seguono le nuove ricerche;
due prove nuove coprono una foto convertita e un fotogramma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 23:08:38 +01:00
1 parent 704c1ed9cf
commit b746aff45d
19 files changed
+1941 -257

No files matched your search

+15 -4
View File
@@ -137,10 +137,21 @@ internal static class ExportFilterSql
private static string OneOnlyMatch(ExportFilterContext x) =>
$"((c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id) OR (c.account_id IS NOT NULL AND c.account_id <> e.account_id))";
/// <summary>The last copy of the file in its effective destination failed («Non riuscito»): «Copia in…» tries again.</summary>
/// <summary>
/// The last copy of the file in its effective destination failed («Non riuscito»), in any form but a frame: «Copia
/// in…» tries again.
/// </summary>
public static string Failed(ExportFilterContext x) => !x.HasFailed
? "0"
: $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id AND c.state = 'Failed')";
: $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id AND c.state = 'Failed' AND c.variant <> 'Frame')";
/// <summary>
/// A frame of the file is copied in its effective destination (decision D4 of tappa E3): it never makes the file
/// copied, only the mark «Solo fotogrammi» of a file not copied otherwise. «Una copia sola» does not apply to frames.
/// </summary>
public static string FrameCopied(ExportFilterContext x) => !x.HasCopies
? "0"
: $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id AND c.state = 'Copied' AND c.variant = 'Frame')";
/// <summary>
/// «Tolto o superato»: not copied, not failed, and its copy in the effective destination was removed, or a copy was
@@ -286,9 +297,9 @@ internal static class ExportFilterSql
{
var destination = DestinationOf(x);
var removed = $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id = {destination} AND c.account_id = e.account_id "
+ "AND c.state IN ('Removed', 'Superseded'))";
+ "AND c.state IN ('Removed', 'Superseded') AND c.variant <> 'Frame')";
var superseded = $"EXISTS (SELECT 1 FROM export_copy c WHERE c.superseded_by_sha256 = m.sha256 AND c.destination_id = {destination} AND c.account_id = e.account_id "
+ "AND c.state IN ('Superseded', 'Removed'))";
+ "AND c.state IN ('Superseded', 'Removed') AND c.variant <> 'Frame')";
if (!bulk)
{
return $"({removed} OR {superseded})";
+86 -15
View File
@@ -826,6 +826,16 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
public Task<ExportItem?> GetItemAsync(long itemId, CancellationToken ct = default) =>
db.ReadAsync(c => ReadFirst(c.Command($"SELECT {ItemColumns} FROM export_item WHERE id = @id").With("@id", itemId), ReadItem), ct);
/// <summary>The first item of a file of a job in a form (ux_export_item_file).</summary>
internal const string FirstItemSql = "SELECT min(id) FROM export_item WHERE run_id = @r AND media_id = @m AND variant = @v AND format = @f";
public Task<long?> FirstItemIdAsync(long runId, long mediaId, ExportVariant variant, ExportFormat format, CancellationToken ct = default) =>
db.ReadAsync(
c => c.Command(FirstItemSql).With("@r", runId).With("@m", mediaId).With("@v", Sql.Enum(variant)).With("@f", Sql.Enum(format)).ExecuteScalar() is long id
? id
: (long?)null,
ct);
public Task<IReadOnlyList<ExportItem>> ListItemsAsync(ExportItemQuery query, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(query);
@@ -878,13 +888,37 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
internal const string ReplacedCopySql = $"""
SELECT {CopyColumns} FROM export_copy
WHERE superseded_by_sha256 = @h AND destination_id = @d AND account_id = @a AND state IN ('Superseded', 'Removed')
WHERE superseded_by_sha256 = @h AND destination_id = @d AND account_id = @a AND state IN ('Superseded', 'Removed') AND variant <> 'Frame'
ORDER BY id DESC LIMIT 1
""";
/// <summary>
/// The current rows of an original, any form but a frame (decision D3 of tappa E3; @h, @d, @a). INDEXED BY keeps
/// it on ix_export_copy_sha256 (a few rows, sorted): for «ORDER BY id» the planner would read a whole destination.
/// </summary>
internal const string CurrentCopiesAnyFormSql = $"""
SELECT {CopyColumns} FROM export_copy INDEXED BY ix_export_copy_sha256
WHERE source_sha256 = @h AND destination_id = @d AND account_id = @a AND variant <> 'Frame' AND state IN ('Copied', 'Failed')
ORDER BY id DESC
""";
/// <summary>The newest row of an original, any state and any form but a frame (@h, @d, @a).</summary>
internal const string LatestCopyAnyFormSql = $"""
SELECT {CopyColumns} FROM export_copy INDEXED BY ix_export_copy_sha256
WHERE source_sha256 = @h AND destination_id = @d AND account_id = @a AND variant <> 'Frame'
ORDER BY id DESC LIMIT 1
""";
/// <summary>The «Non riuscito» rows of an original that a success leaves stale (@h, @d, @a; the kept identity @v, @f).</summary>
internal const string ClearFailedSql = """
DELETE FROM export_copy
WHERE source_sha256 = @h AND destination_id = @d AND account_id = @a AND variant <> 'Frame' AND state = 'Failed'
AND NOT (variant = @v AND format = @f)
""";
internal const string CopiedElsewhereSql = $"""
SELECT {CopyColumns} FROM export_copy
WHERE source_sha256 = @h AND variant = @v AND format = @f AND state = 'Copied' AND account_id IS NOT NULL
WHERE source_sha256 = @h AND variant <> 'Frame' AND state = 'Copied' AND account_id IS NOT NULL
AND (@a IS NULL OR account_id <> @a)
AND destination_id IN (SELECT id FROM export_destination WHERE removed_at IS NULL AND (scope = 'General' OR account_id IS NOT NULL))
ORDER BY id DESC LIMIT 1
@@ -892,10 +926,13 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
internal const string RecentRunsSql = $"SELECT {RunColumns} FROM export_run ORDER BY started_at DESC, id DESC LIMIT @limit";
/// <summary>The whole copies of a destination for some originals (ix_export_copy_sha256); @d and the list of SHA-256.</summary>
/// <summary>
/// The copies of a destination for some originals, in any form but a frame (ix_export_copy_sha256; decision D3 of
/// tappa E3); @d and the list of SHA-256.
/// </summary>
internal static string CopyStatesSql(string shaList) => $"""
SELECT account_id, source_sha256, state, id FROM export_copy
WHERE source_sha256 IN ({shaList}) AND destination_id = @d AND account_id IS NOT NULL AND variant = 'Whole' AND format = 'Original'
WHERE source_sha256 IN ({shaList}) AND destination_id = @d AND account_id IS NOT NULL AND variant <> 'Frame'
""";
/// <summary>
@@ -906,11 +943,12 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
internal static string ReplacedStatesSql(string shaList) => $"""
SELECT account_id, superseded_by_sha256, state, id FROM export_copy
WHERE superseded_by_sha256 IN ({shaList}) AND destination_id = @d AND account_id IS NOT NULL AND +state IN ('Superseded', 'Removed')
AND variant <> 'Frame'
""";
private const string CandidateColumns =
"m.id, m.entry_id, e.account_id, e.kind, m.kind, m.state, m.sha256, m.bytes, m.relative_path, m.position, "
+ "EXISTS (SELECT 1 FROM highlight_entry he WHERE he.entry_id = e.id)";
+ "EXISTS (SELECT 1 FROM highlight_entry he WHERE he.entry_id = e.id), m.duration_ms";
private static ExportCandidate ReadCandidate(SqliteDataReader r) => new(
r.GetInt64(0),
@@ -923,7 +961,8 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
r.GetInt64OrNull(7),
r.GetTextOrNull(8),
r.GetInt32(9),
r.GetBool(10));
r.GetBool(10),
r.GetDurationOrNull(11));
public Task<IReadOnlyDictionary<long, bool>> ListAccountExportSwitchesAsync(CancellationToken ct = default) =>
db.ReadAsync<IReadOnlyDictionary<long, bool>>(
@@ -948,16 +987,44 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
ct);
}
public Task<ExportCopy?> FindCopiedElsewhereAsync(string sha256, ExportVariant variant, ExportFormat format, long? exceptAccountId = null, CancellationToken ct = default)
public Task<ExportCopy?> FindCopiedElsewhereAsync(string sha256, long? exceptAccountId = null, CancellationToken ct = default)
{
var sha = ExportValues.Sha(sha256, nameof(sha256));
return db.ReadAsync(
c => ReadFirst(
c.Command(CopiedElsewhereSql).With("@h", sha).With("@v", Sql.Enum(variant)).With("@f", Sql.Enum(format)).With("@a", Sql.Int(exceptAccountId)),
c.Command(CopiedElsewhereSql).With("@h", sha).With("@a", Sql.Int(exceptAccountId)),
ReadCopy),
ct);
}
public Task<IReadOnlyList<ExportCopy>> ListCurrentCopiesAnyFormAsync(long destinationId, long accountId, string sha256, CancellationToken ct = default)
{
var sha = ExportValues.Sha(sha256, nameof(sha256));
return db.ReadAsync<IReadOnlyList<ExportCopy>>(
c => ReadAll(c.Command(CurrentCopiesAnyFormSql).With("@h", sha).With("@d", destinationId).With("@a", accountId), ReadCopy),
ct);
}
public Task<ExportCopy?> FindLatestCopyAnyFormAsync(long destinationId, long accountId, string sha256, CancellationToken ct = default)
{
var sha = ExportValues.Sha(sha256, nameof(sha256));
return db.ReadAsync(
c => ReadFirst(c.Command(LatestCopyAnyFormSql).With("@h", sha).With("@d", destinationId).With("@a", accountId), ReadCopy),
ct);
}
public Task<int> ClearFailedAsync(long destinationId, long accountId, string sha256, ExportCopyIdentity except, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(except);
var sha = ExportValues.Sha(sha256, nameof(sha256));
return db.WriteAsync(
w => w.Command(ClearFailedSql)
.With("@h", sha).With("@d", destinationId).With("@a", accountId)
.With("@v", Sql.Enum(except.Variant)).With("@f", Sql.Enum(except.Format))
.ExecuteNonQuery(),
ct);
}
public Task<IReadOnlyDictionary<(long AccountId, string Sha256), ExportCopyState>> GetCopyStatesAsync(
long destinationId,
IReadOnlyCollection<(long AccountId, string Sha256)> keys,
@@ -968,8 +1035,9 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
return db.ReadAsync<IReadOnlyDictionary<(long AccountId, string Sha256), ExportCopyState>>(
c =>
{
// Per pair: the current row (Copied or Failed), else the newest row when Removed or Superseded, else a row
// replaced by this file. Rows of other accounts that share a SHA-256 are read and dropped here.
// Per pair, over every form but a frame (D3 of tappa E3): a Copied row, else a Failed one, else the newest
// row when Removed or Superseded, else a row replaced by this file. Rows of other accounts that share a
// SHA-256 are read and dropped here.
var current = new Dictionary<(long, string), ExportCopyState>();
var newest = new Dictionary<(long, string), (long Id, ExportCopyState State)>();
var replaced = new Dictionary<(long, string), (long Id, ExportCopyState State)>();
@@ -1000,7 +1068,7 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
{
Read(CopyStatesSql, chunk, (key, state, id) =>
{
if (state is ExportCopyState.Copied or ExportCopyState.Failed)
if (state == ExportCopyState.Copied || (state == ExportCopyState.Failed && !current.ContainsKey(key)))
{
current[key] = state;
}
@@ -1134,12 +1202,15 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
return marks;
}
var copied = ExportFilterSql.Copied(x);
var frames = ExportFilterSql.FrameCopied(x);
foreach (var chunk in entryIds.Distinct().Chunk(IdChunk))
{
using var command = c.Command(string.Empty);
var list = command.AddList("x", chunk);
command.CommandText = $"""
SELECT m.entry_id, COUNT(*), SUM(CASE WHEN {ExportFilterSql.Copied(x)} THEN 1 ELSE 0 END)
SELECT m.entry_id, COUNT(*), SUM(CASE WHEN {copied} THEN 1 ELSE 0 END),
SUM(CASE WHEN NOT {copied} AND {frames} THEN 1 ELSE 0 END)
FROM media m JOIN entry e ON e.id = m.entry_id
WHERE m.entry_id IN ({list}) AND {ExportFilterSql.DueFile(x)}
GROUP BY m.entry_id
@@ -1147,7 +1218,7 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
using var r = command.ExecuteReader();
while (r.Read())
{
marks[r.GetInt64(0)] = new ExportEntryCopies(r.GetInt32(1), r.GetInt32(2));
marks[r.GetInt64(0)] = new ExportEntryCopies(r.GetInt32(1), r.GetInt32(2), r.GetInt32(3));
}
}
@@ -1174,13 +1245,13 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
using var command = c.Command(string.Empty);
var list = command.AddList("x", chunk);
command.CommandText = $"""
SELECT m.id, {ExportFilterSql.Copied(x)} FROM media m JOIN entry e ON e.id = m.entry_id
SELECT m.id, {ExportFilterSql.Copied(x)}, {ExportFilterSql.FrameCopied(x)} FROM media m JOIN entry e ON e.id = m.entry_id
WHERE m.id IN ({list}) AND {ExportFilterSql.DueFile(x)}
""";
using var r = command.ExecuteReader();
while (r.Read())
{
marks[r.GetInt64(0)] = r.GetInt64(1) != 0 ? ExportMark.Copied : ExportMark.None;
marks[r.GetInt64(0)] = r.GetInt64(1) != 0 ? ExportMark.Copied : r.GetInt64(2) != 0 ? ExportMark.FrameOnly : ExportMark.None;
}
}