Skip to content

Commit c1a22dd

Browse files
myieyeclaude
andcommitted
Diff IsMain in publication sync instead of special-casing it
DiffToUpdate now carries the false->true promotion like any other field (the CRDT side turns it into a SetMainPublicationChange), so the collection-level promotion special-case is removed. A main is never demoted, so there's no 1->0 handling to add. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5f0173b commit c1a22dd

1 file changed

Lines changed: 4 additions & 18 deletions

File tree

backend/FwLite/MiniLcm/SyncHelpers/PublicationSync.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,10 @@ public static async Task<int> Sync(Publication[] beforePublications,
99
Publication[] afterPublications,
1010
IMiniLcmApi api)
1111
{
12-
var changes = await DiffCollection.Diff(
12+
return await DiffCollection.Diff(
1313
beforePublications,
1414
afterPublications,
1515
new PublicationsDiffApi(api));
16-
17-
// Sync the IsMain flag: if "after" has a main but "before" does not, promote it.
18-
// A main that's new to this collection was already created with IsMain set (PublicationsDiffApi.Add),
19-
// so only promote one that already existed but wasn't yet the main — otherwise we'd redundantly update
20-
// a publication that doesn't exist yet (e.g. it throws during a dry-run sync).
21-
var beforeMain = beforePublications.FirstOrDefault(p => p.IsMain);
22-
var afterMain = afterPublications.FirstOrDefault(p => p.IsMain);
23-
24-
if (afterMain is not null && beforeMain is null && beforePublications.Any(p => p.Id == afterMain.Id))
25-
{
26-
await api.UpdatePublication(afterMain.Id,
27-
new UpdateObjectInput<Publication>().Set(p => p.IsMain, true));
28-
changes++;
29-
}
30-
31-
return changes;
3216
}
3317

3418
public static async Task<int> Sync(
@@ -51,7 +35,9 @@ public static async Task<int> Sync(
5135
beforePublication.Name,
5236
afterPublication.Name));
5337

54-
// IsMain is intentionally not diffed here: it transitions only 0->1, handled once in the collection-level Sync.
38+
if (beforePublication.IsMain != afterPublication.IsMain)
39+
patchDocument.Replace(p => p.IsMain, afterPublication.IsMain);
40+
5541
if (patchDocument.Operations.Count == 0) return null;
5642
return new UpdateObjectInput<Publication>(patchDocument);
5743
}

0 commit comments

Comments
 (0)