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

+24
View File
@@ -39,6 +39,30 @@ public abstract class NestServerClient : IDisposable
throw tooOld();
}
/// <summary>
/// GETs <paramref name="relative"/> and reads its body, or returns null on a 404 once
/// <paramref name="throwIfServerTooOld"/> (when given) has found the server new enough.
/// </summary>
private protected async Task<T?> GetOrNullAsync<T>(string relative, string action,
Func<HttpResponseMessage, CancellationToken, Task<T>> read,
Func<CancellationToken, Task>? throwIfServerTooOld, CancellationToken cancellationToken)
where T : class?
{
using var response = await _httpClient.GetAsync(Url(relative), cancellationToken);
if (response.StatusCode == HttpStatusCode.NotFound)
{
if (throwIfServerTooOld is not null)
await throwIfServerTooOld(cancellationToken);
return null;
}
await NestServerHttp.EnsureSuccessAsync(response, action, cancellationToken);
return await read(response, cancellationToken);
}
/// <summary>A <see cref="GetOrNullAsync"/> reader for a raw body.</summary>
private protected static Task<byte[]> ReadBytesAsync(HttpResponseMessage response, CancellationToken cancellationToken) =>
response.Content.ReadAsByteArrayAsync(cancellationToken);
private protected static void ThrowIfInvalidQuery(string? error)
{
if (error is not null)