Skip to content

Commit 5f0173b

Browse files
myieyeclaude
andcommitted
Only rebuild the publication patch when an IsMain op is present
Skip allocating a filtered JsonPatchDocument on the common update that doesn't touch IsMain. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cc72724 commit 5f0173b

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,21 @@ public async Task<Publication> UpdatePublication(Guid id, UpdateObjectInput<Publ
195195
await using var repo = await repoFactory.CreateRepoAsync();
196196
var pub = await repo.GetPublication(id) ?? throw NotFoundException.ForType<Publication>(id);
197197

198-
var patch = new JsonPatchDocument<Publication>();
199-
patch.Operations.AddRange(update.Patch.Operations.Where(op =>
200-
!string.Equals(op.Path, $"/{nameof(Publication.IsMain)}", StringComparison.OrdinalIgnoreCase)));
201-
var changes = patch.ToChanges(pub.Id).ToList();
202-
203-
// IsMain is applied via SetMainPublicationChange (which converges), not as a plain field patch.
204-
if (update.TryGetPropertyChange<Publication, bool>(nameof(Publication.IsMain), out var isMain) && isMain)
205-
changes.Add(new SetMainPublicationChange(pub.Id));
206-
207-
if (changes.Count > 0)
208-
await AddChanges(changes);
198+
// IsMain is applied via SetMainPublicationChange (which converges), not as a plain field patch, so it's
199+
// stripped from the patch and translated to that change — but only when an IsMain op is actually present.
200+
if (update.TryGetPropertyChange<Publication, bool>(nameof(Publication.IsMain), out var isMain))
201+
{
202+
var patch = new JsonPatchDocument<Publication>();
203+
patch.Operations.AddRange(update.Patch.Operations.Where(op =>
204+
!string.Equals(op.Path, $"/{nameof(Publication.IsMain)}", StringComparison.OrdinalIgnoreCase)));
205+
var changes = patch.ToChanges(pub.Id).ToList();
206+
if (isMain) changes.Add(new SetMainPublicationChange(pub.Id));
207+
if (changes.Count > 0) await AddChanges(changes);
208+
}
209+
else if (update.Patch.Operations.Count > 0)
210+
{
211+
await AddChanges(update.Patch.ToChanges(pub.Id));
212+
}
209213
return await repo.GetPublication(id) ?? throw NotFoundException.ForType<Publication>($"{id} (invalid patching to a new id?)");
210214
}
211215

0 commit comments

Comments
 (0)