refactor: share duplicated snapshot, history and fetch helpers

- CuttingPlanSnapshot: one private Copy carries every value and init
  property for WithSearchLimits, WithTabLeadOuts, WithPreservedOrder and
  WithTabbedPartsAvoided, keeping the defensive CrossableTabbedParts copy.
- NestPhaseExtensions: DisplayName and ShortName share one attribute
  lookup and keep their own caches.
- NestDatabase: History, DrawingHistory and DrawingSetHistory share
  ReadRevisionPage (count, page query, read rows) under the same lock.
- NestServerClient.GetOrNullAsync: the GET, 404 check-then-null, ensure
  success and read flow used by the Remote* clients.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-28 18:39:56 -05:00
1 parent 409d30d29e
commit 1f7fd248fe
11 files changed
+126 -184

No files matched your search

+10 -28
View File
@@ -170,15 +170,9 @@ public sealed class RemoteDrawingSetStore : NestServerClient, IDrawingSetStore
public async Task<SetReleaseRecord?> GetReleaseAsync(Guid id, CancellationToken cancellationToken = default)
{
if (id == Guid.Empty) throw new ArgumentException("A release id is required.", nameof(id));
using var response = await _httpClient.GetAsync(Url($"api/releases/{id}"), cancellationToken);
if (response.StatusCode == HttpStatusCode.NotFound)
{
await ThrowIfReleasesUnsupported(cancellationToken);
return null;
}
await NestServerHttp.EnsureSuccessAsync(response, $"read release {id}", cancellationToken);
var release = await ReadRelease(response, cancellationToken);
if (release.Id != id)
var release = await GetOrNullAsync($"api/releases/{id}", $"read release {id}", ReadRelease,
ThrowIfReleasesUnsupported, cancellationToken);
if (release is not null && release.Id != id)
throw new IOException("Nest server returned a different release.");
return release;
}
@@ -278,31 +272,19 @@ public sealed class RemoteDrawingSetStore : NestServerClient, IDrawingSetStore
ReadSet, current => new DrawingSetSaveConflictException(current), saved => (saved.Id, saved.Revision),
ThrowIfServerTooOld, cancellationToken);
private async Task<DrawingSetRecord?> GetRecordAsync(string relative, string action, CancellationToken cancellationToken)
{
using var response = await _httpClient.GetAsync(Url(relative), cancellationToken);
if (response.StatusCode == HttpStatusCode.NotFound)
{
await ThrowIfServerTooOld(cancellationToken);
return null;
}
await NestServerHttp.EnsureSuccessAsync(response, action, cancellationToken);
return await ReadSet(response, cancellationToken);
}
private Task<DrawingSetRecord?> GetRecordAsync(string relative, string action, CancellationToken cancellationToken) =>
GetOrNullAsync(relative, action, ReadSet, ThrowIfServerTooOld, cancellationToken);
private async Task<DrawingSetPage?> GetPageAsync(string relative, int offset, int limit, string action,
CancellationToken cancellationToken)
{
NestServerHttp.ValidatePaging(offset, limit, DrawingLibraryRules.MaxRevisionLimit);
using var response = await _httpClient.GetAsync(Url($"{relative}?{NestServerHttp.Paging(offset, limit)}"), cancellationToken);
if (response.StatusCode == HttpStatusCode.NotFound)
{
await ThrowIfServerTooOld(cancellationToken);
var page = await GetOrNullAsync($"{relative}?{NestServerHttp.Paging(offset, limit)}", action,
async (response, token) => await response.Content.ReadFromJsonAsync<DrawingSetPage>(NestServerHttp.JsonOptions, token)
?? throw new IOException("Nest server returned an empty drawing set page."),
ThrowIfServerTooOld, cancellationToken);
if (page is null)
return null;
}
await NestServerHttp.EnsureSuccessAsync(response, action, cancellationToken);
var page = await response.Content.ReadFromJsonAsync<DrawingSetPage>(NestServerHttp.JsonOptions, cancellationToken)
?? throw new IOException("Nest server returned an empty drawing set page.");
if (page.Items is null || !NestServerHttp.IsBoundedPage(page.Items.Count, page.Total, page.Offset, page.Limit, offset, limit)
|| page.Items.Any(item => item is null))
throw new IOException("Nest server returned an invalid or unbounded drawing set page.");