refactor(server): share the by-id scalar query for packages and job results

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-29 12:06:37 -05:00
1 parent 4d921a357c
commit 70ac1c7d6f
3 files changed
+24 -36

No files matched your search

+5 -13
View File
@@ -125,19 +125,11 @@ public sealed partial class NestDatabase
}
}
public byte[]? GetDrawingPackage(Guid id)
{
lock (_sync)
{
using var command = _connection.CreateCommand();
command.CommandText = """
SELECT p.package FROM drawings d JOIN drawing_packages p ON p.sha256 = d.packageSha256
WHERE d.id=$id
""";
command.Parameters.AddWithValue("$id", id.ToString());
return command.ExecuteScalar() as byte[];
}
}
public byte[]? GetDrawingPackage(Guid id) =>
ScalarById("""
SELECT p.package FROM drawings d JOIN drawing_packages p ON p.sha256 = d.packageSha256
WHERE d.id=$id
""", id) as byte[];
/// <summary>One bounded page of matching drawings plus the total, read in one monitor hold.</summary>
public DrawingLibraryPage QueryDrawings(DrawingLibraryQuery query)
+7 -23
View File
@@ -242,31 +242,15 @@ public sealed partial class NestDatabase
/// The job's package while it is queued or running, or succeeded and unreviewed (a desktop
/// reopening the result reads the job from it); other finished jobs no longer keep it.
/// </summary>
public byte[]? GetJobPackage(Guid id)
{
lock (_sync)
{
using var command = _connection.CreateCommand();
command.CommandText = """
SELECT package FROM nest_jobs
WHERE id=$id AND (state IN ('Queued', 'Running') OR (state='Succeeded' AND review=''))
""";
command.Parameters.AddWithValue("$id", id.ToString());
return command.ExecuteScalar() as byte[];
}
}
public byte[]? GetJobPackage(Guid id) =>
ScalarById("""
SELECT package FROM nest_jobs
WHERE id=$id AND (state IN ('Queued', 'Running') OR (state='Succeeded' AND review=''))
""", id) as byte[];
/// <summary>A succeeded, unreviewed job's result; null for any other job.</summary>
public string? GetJobResult(Guid id)
{
lock (_sync)
{
using var command = _connection.CreateCommand();
command.CommandText = "SELECT result FROM nest_jobs WHERE id=$id AND state='Succeeded' AND review=''";
command.Parameters.AddWithValue("$id", id.ToString());
return command.ExecuteScalar() as string;
}
}
public string? GetJobResult(Guid id) =>
ScalarById("SELECT result FROM nest_jobs WHERE id=$id AND state='Succeeded' AND review=''", id) as string;
/// <summary>
/// A queued job is cancelled at once; a running one is marked so its worker stops at the
+12
View File
@@ -331,6 +331,18 @@ public sealed partial class NestDatabase : IDisposable
command.ExecuteNonQuery();
}
/// <summary>The first column of the first row <paramref name="sql"/> selects for <c>$id</c>, or null.</summary>
private object? ScalarById(string sql, Guid id)
{
lock (_sync)
{
using var command = _connection.CreateCommand();
command.CommandText = sql;
command.Parameters.AddWithValue("$id", id.ToString());
return command.ExecuteScalar();
}
}
private void Migrate()
{
lock (_sync)