fix(proxies): judge proxies by one rule and record tiers and reports as they stand
- ArchiveImages.IsProxyOf compares capture times to the microsecond the index
keeps (sidecars and Exif keep 100 ns ticks), and for frames read through
proxies also applies the policy's size rule, so the proxy pass, uploads,
thumbnails, renders, analyses, tiers, manifests and downloads agree.
- Proxy headers are cached per file while length and write time are unchanged
(and the file has settled), so manifests cost a stat per proxy.
- FrameTiers.RecordAsync checks proxy presence when it writes the sidecar and
returns the sequence's frames as they are, so a deep analysis or render that
ran while proxies arrived no longer flags the frames preview-only again, and
the analysis advises from the current flags.
- Server manifests ignore ProxiesBuilt for frames the server cannot decode, so
frames added since the last proxy pass are asked for their proxies.
- GET /sequences/{id}/analysis/report answers 404 for a report that found
frames unreadable before their proxies arrived (DeepReports.ReadCurrentAsync).
- The deep checkpoint key marks only frames read from proxies, so checkpoints
written by earlier versions still resume.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
16 files changed
+514
-99
No files matched your search
@@ -0,0 +1,28 @@
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Model;
|
||||
|
||||
namespace Titano.Data.Processing;
|
||||
|
||||
/// <summary>
|
||||
/// Saved deep-analysis reports (<c>.titano/analysis.json</c>, BRIEF §10.2) for hosts that hand them on: a server serves
|
||||
/// one to the editors of its clients only while it still describes the sequence (§14.5).
|
||||
/// </summary>
|
||||
public static class DeepReports
|
||||
{
|
||||
/// <summary>
|
||||
/// The saved report of <paramref name="sequence"/> when it describes its frames as a host with
|
||||
/// <paramref name="decoder"/> reads them now; null when there is none, it covers another number of frames, or it
|
||||
/// found unreadable a frame that has been read from its proxy since (an original that host cannot decode, whose proxy
|
||||
/// arrived after the analysis): its verdict and its advice to exclude that frame no longer hold.
|
||||
/// </summary>
|
||||
public static async Task<DeepAnalysisReport?> ReadCurrentAsync(TitanoDatabase db, Archive archive, Sequence sequence, ImageDecoder decoder,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(archive);
|
||||
ArgumentNullException.ThrowIfNull(sequence);
|
||||
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, decoder, cancellationToken).ConfigureAwait(false);
|
||||
return SequenceAnalyser.ReadReport(new ArchivePaths(archive.RootPath).Sequence(sequence.Folder), frames);
|
||||
}
|
||||
}
|
||||
@@ -94,11 +94,12 @@ internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions opti
|
||||
if (render.StandIns.Count > 0)
|
||||
context.Log(Loc.L("Export.Log.StandIns", string.Join(", ", render.StandIns.Select(i => (i + 1).ToString(Loc.Culture)))));
|
||||
// Recorded without the job's token: what decoding found holds even if the job is cancelled meanwhile, and a
|
||||
// sidecar that cannot be written now only leaves it to the next analysis or render.
|
||||
// sidecar that cannot be written now only leaves it to the next analysis or render. A frame decoded from its
|
||||
// preview whose proxy arrived during the render is not preview-only: FrameTiers looks for the proxy as it records.
|
||||
try
|
||||
{
|
||||
var decoded = render.Decoded.ToDictionary(kv => frames.Frames[kv.Key].Id, kv => kv.Value);
|
||||
await tiers.RecordAsync(archive, sequence, decoded, CancellationToken.None).ConfigureAwait(false);
|
||||
await tiers.RecordAsync(archive, sequence, decoded, proxies: false, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or LeaseUnavailableException
|
||||
or ArchiveOfflineException)
|
||||
|
||||
@@ -46,17 +46,18 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, options.Archive.Decoder, cancellationToken).ConfigureAwait(false);
|
||||
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders. A frame
|
||||
// read from its proxy is not preview-only whatever its original's tier, so it caps nothing (BRIEF §8.1, §8.2).
|
||||
// read from its proxy is not preview-only whatever its original's tier, so it caps nothing (BRIEF §8.1, §8.2); the
|
||||
// flags are taken as the sidecar has them once recorded, so ones another worker recorded meanwhile count too.
|
||||
var probed = await _tiers.ProbeUnknownAsync(archive, folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken).ConfigureAwait(false);
|
||||
var proxied = frames.ProxyStates(options.Archive.Decoder);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, proxied, cancellationToken).ConfigureAwait(false));
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, proxies: true, cancellationToken).ConfigureAwait(false));
|
||||
var metadata = frames.LightFrames();
|
||||
|
||||
DeepAnalysisReport? report;
|
||||
if (deep)
|
||||
{
|
||||
// Proxies may have arrived during the pass: the advice below follows the frames as they are at its end.
|
||||
(report, var decoded) = await AnalyseDeepAsync(archive, frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, proxied, cancellationToken).ConfigureAwait(false));
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, proxies: true, cancellationToken).ConfigureAwait(false));
|
||||
metadata = [.. metadata.Select((m, i) => m with { Flags = frames.Frames[i].Flags })];
|
||||
}
|
||||
else
|
||||
@@ -139,11 +140,11 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The frame rows with the tier fields of <paramref name="changed"/> sidecar frames.</summary>
|
||||
private static SequenceFrames WithTiers(SequenceFrames frames, IReadOnlyList<SidecarFrame> changed)
|
||||
/// <summary>The frame rows with the flags and preview sizes of the <paramref name="current"/> sidecar frames.</summary>
|
||||
private static SequenceFrames WithTiers(SequenceFrames frames, IReadOnlyList<SidecarFrame> current)
|
||||
{
|
||||
if (changed.Count == 0) return frames;
|
||||
var byId = changed.ToDictionary(f => f.Id);
|
||||
if (current.Count == 0) return frames;
|
||||
var byId = current.ToDictionary(f => f.Id);
|
||||
var rows = frames.Frames.Select(f => byId.TryGetValue(f.Id, out var s)
|
||||
? f with { Flags = s.Flags, PreviewWidth = s.PreviewW ?? 0, PreviewHeight = s.PreviewH ?? 0 }
|
||||
: f).ToList();
|
||||
@@ -215,15 +216,16 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
|
||||
/// <summary>Identity of the analysed content: frames replaced or renumbered since a checkpoint was written (with the
|
||||
/// same count), or now read from their proxies where they were read from their originals (or the other way round),
|
||||
/// make it stale, like changed options do.</summary>
|
||||
private static string ContentKey(SequenceFrames frames)
|
||||
/// make it stale, like changed options do. Only frames read from proxies are marked, so the key of a sequence read
|
||||
/// from its originals is what it was before proxies counted, and checkpoints written then still resume.</summary>
|
||||
internal static string ContentKey(SequenceFrames frames)
|
||||
{
|
||||
using var hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
{
|
||||
var f = frames.Frames[i];
|
||||
var source = frames.Proxied is { } proxied && proxied[i] ? "proxy" : "original";
|
||||
hash.AppendData(Encoding.UTF8.GetBytes($"{f.Id:N}/{f.Sha256}/{f.Size}/{f.Flags & SequenceFrames.NotAnalysed}/{source};"));
|
||||
var source = frames.Proxied is { } proxied && proxied[i] ? "/proxy" : "";
|
||||
hash.AppendData(Encoding.UTF8.GetBytes($"{f.Id:N}/{f.Sha256}/{f.Size}/{f.Flags & SequenceFrames.NotAnalysed}{source};"));
|
||||
}
|
||||
return Convert.ToHexStringLower(hash.GetHashAndReset())[..16];
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
|
||||
/// Every frame row of <paramref name="sequence"/> with its archive file: the proxy when asked, and whenever the
|
||||
/// original is one <paramref name="decoder"/> cannot decode (<see cref="ArchiveImages.NeedsProxy(ImageDecoder, ImageFileFormat)"/>:
|
||||
/// HEIF on the server, BRIEF §2.3, §8.5), as long as the frame's own proxy is there (<see cref="ArchiveImages.IsProxyOf"/>:
|
||||
/// not one left at its index by a frame renumbered since); else the original.
|
||||
/// not one left at its index by a frame renumbered since, nor, for an original this host cannot decode, one smaller
|
||||
/// than the archive's policy); else the original.
|
||||
/// </summary>
|
||||
public static async Task<SequenceFrames> LoadAsync(TitanoDatabase db, Archive archive, Sequence sequence, bool useProxies, ImageDecoder decoder,
|
||||
CancellationToken cancellationToken)
|
||||
@@ -46,13 +47,16 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
|
||||
var files = new string?[frames.Count];
|
||||
var originals = new string?[frames.Count];
|
||||
var proxied = new bool[frames.Count];
|
||||
ProxyPolicy? policy = null;
|
||||
for (var i = 0; i < files.Length; i++)
|
||||
{
|
||||
var frame = frames[i];
|
||||
if ((frame.Flags & FrameFlags.Missing) != 0) continue;
|
||||
originals[i] = paths.FromRelative(frame.RelativePath);
|
||||
var proxy = useProxies || ArchiveImages.NeedsProxy(decoder, frame.Format) ? folder.Proxy(frame.Index) : null;
|
||||
proxied[i] = proxy is not null && ArchiveImages.IsProxyOf(proxy, frame.CapturedAt);
|
||||
var needs = ArchiveImages.NeedsProxy(decoder, frame.Format);
|
||||
var proxy = useProxies || needs ? folder.Proxy(frame.Index) : null;
|
||||
proxied[i] = proxy is not null && ArchiveImages.IsProxyOf(proxy, frame.CapturedAt, frame.Width, frame.Height,
|
||||
needs ? policy ??= ManifestStore.ReadArchive(paths.ManifestPath).ProxyPolicy : null);
|
||||
files[i] = proxied[i] ? proxy : originals[i];
|
||||
}
|
||||
return new SequenceFrames(sequence, frames, files) { Proxied = proxied, Originals = originals };
|
||||
@@ -95,22 +99,6 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
|
||||
return light;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// By frame id, whether each frame whose original <paramref name="decoder"/> cannot decode (it is read from its proxy,
|
||||
/// <see cref="LoadAsync"/>) has its own proxy now: what its <see cref="FrameFlags.PreviewOnly"/> follows
|
||||
/// (<see cref="FrameTiers.RecordAsync(Archive, Sequence, IReadOnlyDictionary{Guid, FileTier}, IReadOnlyDictionary{Guid, bool}?, CancellationToken)"/>).
|
||||
/// Missing frames are left out.
|
||||
/// </summary>
|
||||
public Dictionary<Guid, bool> ProxyStates(ImageDecoder decoder)
|
||||
{
|
||||
var states = new Dictionary<Guid, bool>();
|
||||
for (var i = 0; i < Frames.Count; i++)
|
||||
{
|
||||
if (Files[i] is not null && ArchiveImages.NeedsProxy(decoder, Frames[i].Format)) states[Frames[i].Id] = Proxied is { } proxied && proxied[i];
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
/// <summary>Positions of the frames a render must skip besides the project's exclusions.</summary>
|
||||
public IEnumerable<int> NotRenderable()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user