feat: owner review 2 phase 5a: workspace and projects with a local home (#14)
CI / Build and test (push) Successful in 9m43s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 27s
CI / PostgreSQL 16 integration (push) Failing after 8m41s
CI / PostgreSQL 17 integration (push) Successful in 12m37s
CI / Docker image (push) Successful in 56s
Release / Build, test and publish (push) Successful in 14m59s
Release / Server image (push) Successful in 1m51s

Edit opens a sequence as a project of a workspace folder outside the library. Projects have linear version histories kept as sidecars in .chronos/projects/, Main mirrors the sequence's settings, and sync merges setting by setting. Migration 0009, JobKind.WorkspaceCopy = 20, Settings › Workspace, and 241 new strings in 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #14.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-04 09:22:08 +01:00
1 parent efa87f68ce
commit 9b24cf74fc
370 files changed
+29237 -287

No files matched your search

@@ -238,6 +238,26 @@ public sealed class FrameRepository
return await session.ExecuteAsync("DELETE FROM frames WHERE sequence_id = $1 AND idx < 0", [sequenceId], cancellationToken).ConfigureAwait(false);
}, cancellationToken);
/// <summary>
/// How many photos of a sequence the index has hashed, a checksum of those hashes (it moves when one is replaced in
/// place, as a Verify that finds other bytes does), and how many removals (tombstones) it keeps for it: with the frames
/// version, what decides how project positions name its photos (<see cref="Projects.IProjectHome.FramesStampAsync"/>).
/// The checksum sums the first five hex digits of each hash weighted by the frame's place, in SQL both dialects read.
/// </summary>
public Task<(long Hashed, long Checksum, long Removals)> CountNamedAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
_db.RunAsync(async session =>
{
var find = _db.Sql.IsPostgres ? "strpos" : "instr";
string Digit(int at) => $"{find}('0123456789abcdef', lower(substr(sha256, {at}, 1)))";
var row = await session.QuerySingleAsync(
"SELECT (SELECT count(sha256) FROM frames WHERE sequence_id = $1), " +
$"(SELECT CAST(COALESCE(SUM(CAST(idx % 1000 + 1 AS bigint) * ({Digit(1)} * 65536 + {Digit(2)} * 4096 + {Digit(3)} * 256 + {Digit(4)} * 16 + {Digit(5)})), 0) AS bigint) " +
"FROM frames WHERE sequence_id = $1), " +
"(SELECT count(*) FROM frame_removals WHERE sequence_id = $1)",
[sequenceId], cancellationToken).ConfigureAwait(false);
return (row.GetInt64(0), row.GetInt64(1), row.GetInt64(2));
}, cancellationToken);
/// <summary>Number of frames of a sequence.</summary>
public async Task<int> CountBySequenceAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
(int)await _db.ScalarAsync<long>("SELECT count(*) FROM frames WHERE sequence_id = $1", [sequenceId], cancellationToken).ConfigureAwait(false);
@@ -235,6 +235,13 @@ public sealed class JobRepository
return await _db.ScalarAsync<long>(sql, p.ToArray(), cancellationToken).ConfigureAwait(false) > 0;
}
/// <summary>The queued, running and paused jobs of <paramref name="kind"/> that target <paramref name="targetId"/>, newest first (5000 at most).</summary>
public Task<IReadOnlyList<Job>> ListPendingAsync(JobKind kind, Guid targetId, CancellationToken cancellationToken = default) =>
// Target ids are stored comma-joined as lower-case text, which never holds a LIKE wildcard.
_db.ListAsync(
$"SELECT {Columns} FROM jobs WHERE kind = $1 AND state IN ({PendingStates}) AND target_ids LIKE $2 ESCAPE '\\' ORDER BY created DESC, id DESC LIMIT 5000",
[(int)kind, SqlDialect.ContainsPattern(targetId.ToString())], Map, cancellationToken);
/// <summary>
/// What the running and paused jobs hold, but the job <paramref name="except"/> (the one asking): each one's id, kind and
/// targets, and only a verify's parameters (<see cref="JobHold"/>). Neither the other parameters nor the targets of
@@ -0,0 +1,149 @@
using Chronos.Core.Model;
namespace Chronos.Data.Repositories;
/// <summary>
/// Projects of sequences and their versions (owner review 2, R8; <c>projects</c>, <c>project_versions</c>). The sidecars
/// in <c>.chronos/projects/</c> are the truth and are written first (<c>Projects.ProjectService</c>); these rows are
/// derived, rebuilt from the sidecars, and go with the sequence's row.
/// </summary>
public sealed class ProjectRepository
{
private const string Columns =
"id, sequence_id, name, is_main, head_version_id, head_number, mirrored_settings_version, mirrored_version_id, created_by, created_at, " +
"updated_at, deleted_at";
private const string VersionColumns =
"id, project_id, parent_id, number, kind, author, client_name, note, settings_json, content_hash, settings_format, frames_version, " +
"restored_from, created_at, stored_at";
private readonly DbAccess _db;
internal ProjectRepository(DbAccess db) => _db = db;
/// <summary>The projects of a sequence: Main first, then the others oldest first; deleted ones only when asked.</summary>
public Task<IReadOnlyList<SequenceProject>> ListBySequenceAsync(Guid sequenceId, bool includeDeleted = false, CancellationToken cancellationToken = default) =>
_db.ListAsync($"SELECT {Columns} FROM projects WHERE sequence_id = $1{(includeDeleted ? string.Empty : " AND deleted_at IS NULL")} " +
"ORDER BY is_main DESC, created_at, id", [sequenceId], Map, cancellationToken);
public Task<SequenceProject?> GetAsync(Guid id, CancellationToken cancellationToken = default) =>
_db.SingleAsync($"SELECT {Columns} FROM projects WHERE id = $1", [id], Map, cancellationToken);
/// <summary>The Main project of a sequence; null until it is made.</summary>
public Task<SequenceProject?> GetMainAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
_db.SingleAsync($"SELECT {Columns} FROM projects WHERE sequence_id = $1 AND is_main = $2 AND deleted_at IS NULL", [sequenceId, true], Map,
cancellationToken);
/// <summary>Adds a project; a name or a Main another live project of the sequence has already fails (unique).</summary>
public Task InsertAsync(SequenceProject project, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(project);
return _db.ExecuteAsync($"INSERT INTO projects ({Columns}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
[
project.Id, project.SequenceId, project.Name, project.IsMain, project.HeadVersionId, project.HeadNumber, project.MirroredSettingsVersion,
project.MirroredVersionId, project.CreatedBy, project.CreatedAt, project.UpdatedAt, project.DeletedAt,
], cancellationToken);
}
/// <summary>Stores every field of <paramref name="project"/> but its id, sequence and creation; false when it is gone.</summary>
public async Task<bool> UpdateAsync(SequenceProject project, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(project);
return await _db.ExecuteAsync(
"UPDATE projects SET name = $2, is_main = $3, head_version_id = $4, head_number = $5, mirrored_settings_version = $6, mirrored_version_id = $7, " +
"updated_at = $8, deleted_at = $9 WHERE id = $1",
[
project.Id, project.Name, project.IsMain, project.HeadVersionId, project.HeadNumber, project.MirroredSettingsVersion,
project.MirroredVersionId, project.UpdatedAt, project.DeletedAt,
], cancellationToken).ConfigureAwait(false) > 0;
}
/// <summary>
/// Moves the head to <paramref name="headId"/> (number <paramref name="headNumber"/>) only while it is still at
/// <paramref name="expectedNumber"/>: two writers never both advance it from the same head. False when it moved.
/// </summary>
public async Task<bool> AdvanceHeadAsync(Guid projectId, int expectedNumber, Guid headId, int headNumber, DateTimeOffset at,
CancellationToken cancellationToken = default) =>
await _db.ExecuteAsync("UPDATE projects SET head_version_id = $2, head_number = $3, updated_at = $4 WHERE id = $1 AND head_number = $5",
[projectId, headId, headNumber, at, expectedNumber], cancellationToken).ConfigureAwait(false) > 0;
/// <summary>Records the version and the sequence's settings version a Main project's head was last mirrored with.</summary>
public async Task<bool> SetMirroredAsync(Guid projectId, Guid? versionId, int settingsVersion, CancellationToken cancellationToken = default) =>
await _db.ExecuteAsync("UPDATE projects SET mirrored_version_id = $2, mirrored_settings_version = $3 WHERE id = $1",
[projectId, versionId, settingsVersion], cancellationToken).ConfigureAwait(false) > 0;
/// <summary>Adds a version; a number or id the project has already fails (unique).</summary>
public Task InsertVersionAsync(ProjectVersion version, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(version);
return _db.ExecuteAsync($"INSERT INTO project_versions ({VersionColumns}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
[
version.Id, version.ProjectId, version.ParentId, version.Number, ProjectVersionKinds.Name(version.Kind), version.Author, version.ClientName,
version.Note, DbParam.Text(version.SettingsJson), version.ContentHash, version.SettingsFormat, version.FramesVersion, version.RestoredFrom,
version.CreatedAt, version.StoredAt ?? version.CreatedAt,
], cancellationToken);
}
public Task<ProjectVersion?> GetVersionAsync(Guid id, CancellationToken cancellationToken = default) =>
_db.SingleAsync($"SELECT {VersionColumns} FROM project_versions WHERE id = $1", [id], MapVersion, cancellationToken);
public Task<ProjectVersion?> GetVersionByNumberAsync(Guid projectId, int number, CancellationToken cancellationToken = default) =>
_db.SingleAsync($"SELECT {VersionColumns} FROM project_versions WHERE project_id = $1 AND number = $2", [projectId, number], MapVersion,
cancellationToken);
/// <summary>
/// One page of a project's history, newest first: the versions numbered below <paramref name="beforeNumber"/> (all
/// when null), at most <paramref name="limit"/> (1–1000).
/// </summary>
public Task<IReadOnlyList<ProjectVersion>> ListVersionsAsync(Guid projectId, int? beforeNumber, int limit, CancellationToken cancellationToken = default) =>
_db.ListAsync($"SELECT {VersionColumns} FROM project_versions WHERE project_id = $1 AND number < $2 ORDER BY number DESC LIMIT $3",
[projectId, beforeNumber ?? int.MaxValue, Cursor.ClampLimit(limit)], MapVersion, cancellationToken);
/// <summary>The versions numbered above <paramref name="afterNumber"/>, oldest first, at most <paramref name="limit"/> (1–1000): what a pull takes.</summary>
public Task<IReadOnlyList<ProjectVersion>> ListVersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken = default) =>
_db.ListAsync($"SELECT {VersionColumns} FROM project_versions WHERE project_id = $1 AND number > $2 ORDER BY number LIMIT $3",
[projectId, afterNumber, Cursor.ClampLimit(limit)], MapVersion, cancellationToken);
/// <summary>The id of each version of a project by number (the index's side of a comparison with the sidecars).</summary>
public async Task<IReadOnlyDictionary<int, Guid>> ListVersionIdsAsync(Guid projectId, CancellationToken cancellationToken = default)
{
var rows = await _db.ListAsync("SELECT number, id FROM project_versions WHERE project_id = $1", [projectId], r => (r.GetInt32(0), r.GetGuid(1)),
cancellationToken).ConfigureAwait(false);
return rows.ToDictionary(r => r.Item1, r => r.Item2);
}
private static SequenceProject Map(DbRow r) => new()
{
Id = r.GetGuid(0),
SequenceId = r.GetGuid(1),
Name = r.GetString(2),
IsMain = r.GetBool(3),
HeadVersionId = r.GetGuidOrNull(4),
HeadNumber = r.GetInt32(5),
MirroredSettingsVersion = r.GetInt32OrNull(6),
MirroredVersionId = r.GetGuidOrNull(7),
CreatedBy = r.GetStringOrNull(8),
CreatedAt = r.GetDateTimeOffset(9),
UpdatedAt = r.GetDateTimeOffset(10),
DeletedAt = r.GetDateTimeOffsetOrNull(11),
};
private static ProjectVersion MapVersion(DbRow r) => new()
{
Id = r.GetGuid(0),
ProjectId = r.GetGuid(1),
ParentId = r.GetGuidOrNull(2),
Number = r.GetInt32(3),
Kind = ProjectVersionKinds.Parse(r.GetStringOrNull(4)),
Author = r.GetStringOrNull(5),
ClientName = r.GetStringOrNull(6),
Note = r.GetStringOrNull(7),
SettingsJson = r.GetString(8),
ContentHash = r.GetString(9),
SettingsFormat = r.GetInt32(10),
FramesVersion = r.GetInt32(11),
RestoredFrom = r.GetGuidOrNull(12),
CreatedAt = r.GetDateTimeOffset(13),
StoredAt = r.GetDateTimeOffset(14),
};
}
@@ -6,7 +6,8 @@ namespace Chronos.Data.Repositories;
public sealed class RenderRepository
{
private const string Columns =
"id, sequence_id, preset_name, settings_json, output_path, codec, width, height, fps, duration_seconds, bytes, created, produced_by";
"id, sequence_id, preset_name, settings_json, output_path, codec, width, height, fps, duration_seconds, bytes, created, produced_by, project_id, " +
"project_version_id";
private const string RecountSql =
"UPDATE sequences SET rendered_count = (SELECT count(*) FROM renders WHERE sequence_id = $1) WHERE id = $1";
@@ -19,10 +20,11 @@ public sealed class RenderRepository
_db.InTransactionAsync(async session =>
{
await LockSequenceAsync(session, render.SequenceId, cancellationToken).ConfigureAwait(false);
await session.ExecuteAsync($"INSERT INTO renders ({Columns}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)",
await session.ExecuteAsync($"INSERT INTO renders ({Columns}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
[
render.Id, render.SequenceId, render.PresetName, DbParam.Json(render.SettingsJson), render.OutputPath, render.Codec,
render.Width, render.Height, render.Fps, render.DurationSeconds, render.Bytes, render.Created, render.ProducedBy,
render.Width, render.Height, render.Fps, render.DurationSeconds, render.Bytes, render.Created, render.ProducedBy, render.ProjectId,
render.ProjectVersionId,
], cancellationToken).ConfigureAwait(false);
return await session.ExecuteAsync(RecountSql, [render.SequenceId], cancellationToken).ConfigureAwait(false);
}, cancellationToken);
@@ -106,5 +108,7 @@ public sealed class RenderRepository
Bytes = r.GetInt64(10),
Created = r.GetDateTimeOffset(11),
ProducedBy = r.GetStringOrNull(12),
ProjectId = r.GetGuidOrNull(13),
ProjectVersionId = r.GetGuidOrNull(14),
};
}