Repository navigation
✨ feat: an aggregate saves the members it changed, never its whole row - #11
Conversation
AggregateRepository remembers what each aggregate it loads or adds maps to, and ModifyAsync writes only the DataModel members whose mapped value changed since, through IPartialModifyRepository. A save that changed nothing writes nothing. An aggregate it did not load, or a native repository without member-scoped writes, keeps the whole-row write unless DomainPersistenceOptions.RefuseWholeRowWrites is on. Proven on PostgreSQL in a container: two saves of one row keep both changes. CI requires those tests on Linux (CORE_DDD_ENGINE_TESTS). Closes #10
…ON element is no value
edgarmesquita
left a comment
There was a problem hiding this comment.
Secondary review, round 1 (Antigravity, Gemini 4 Argon Medium), because Copilot cannot be requested on this repository.
Two findings, both fixed in ff79d72. Nothing dismissed.
| public Task ModifyAsync(TAggregate aggregate, CancellationToken cancellationToken = default) | ||
| public async Task ModifyAsync(TAggregate aggregate, CancellationToken cancellationToken = default) | ||
| { | ||
| _tracker.Track(aggregate); |
There was a problem hiding this comment.
[medium] ModifyAsync tracked the aggregate before deciding whether to write it, so a save refused by RefuseWholeRowWrites (or a stage that threw) left the aggregate tracked, and a later commit would publish its events for a change never written.
Fixed in ff79d72: Add, Modify and Remove track the aggregate once its write is staged, and a save with nothing to write still tracks it. Two tests hold it, and both fail with tracking first.
| case JsonNode node: | ||
| return node.DeepClone(); | ||
| case JsonElement element: | ||
| return new Serialized(element.GetRawText()); |
There was a problem hiding this comment.
[medium] A default JsonElement has no raw text, and its GetRawText() ran outside the try, so every save of a DataModel with an unset JsonElement member threw. JsonElement and JsonDocument also compared by raw text, unlike JsonNode.
Fixed in ff79d72: a default JsonElement is no value, and both are kept as a JsonNode, compared by content. Three tests hold it.
edgarmesquita
left a comment
There was a problem hiding this comment.
Secondary review, round 2 (Antigravity, Gemini 4 Argon Medium), because Copilot cannot be requested on this repository.
No findings. The review closes here.
|
🎉 This PR is included in version 7.2.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #10. Part of eQuantic/equantic-space#760.
OpenSpec change: core-aggregate-saves-changed-members.
What changes
AggregateRepository.ModifyAsyncused to stage the aggregate with the native repository's whole-rowModifyAsync(item). Every column went back as the aggregate mapped it, so a request that loaded a row, changed one thing and saved it undid whatever another request had changed in the same row in between. It also put back the default for a column the aggregate never carries.Now:
GetAsync) or adds (AddAsync) maps to.ModifyAsyncwrites only the DataModel members whose mapped value changed since, throughIPartialModifyRepository(eQuantic.Core.Data 7.1, on every native provider).JsonNodeor a byte array changed in place counts, a date's kind and an offset's offset count. A value that cannot be compared counts as changed, so a doubt costs a write and never loses a change.[Unmapped]members and navigations are never named.DomainPersistenceOptions.RefuseWholeRowWrites, set through the newAddDomainPersistence(options => …), turns both into anInvalidOperationException.Requirements implemented
Version
A minor (7.2.0), as the maintainer decided: no signature changes, and the new option is off by default. A consumer that relied on a save writing back the whole row, its
updatedAtincluded when nothing else changed, sees the new behaviour.Tests
AggregateSavesTests(17) andDomainPersistenceRegistrationTests(2): which members each save names, in-place changes, a failed stage keeping the change for the next save, the fallback and the refusal.eQuantic.Core.Persistence.Engine.Tests(new, net10.0 since eQuantic.Core.Data.PostgreSql 7.1 is net10.0 only): the race, a column the aggregate does not carry, an unchanged save after another request wrote the row, a JSON member changed in place, and the refusal. They run on PostgreSQL 17 in a container. CI requires them on Linux (CORE_DDD_ENGINE_TESTS=required), and Windows runners ignore them because they cannot run the image.