-
Notifications
You must be signed in to change notification settings - Fork 1
Remove reference changes are lost #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe pull request introduces two new test methods in the Changes
Sequence Diagram(s)sequenceDiagram
participant T as Test Method
participant W as WriteNextChange
participant CTX as ChangeContext
participant SW as SnapshotWorker
T->>W: Execute add/update/delete operations
W->>CTX: Initialize ChangeContext with commitIndex & intermediateSnapshots
CTX->>SW: Pass change context for commit processing
SW->>SW: Generate snapshot for updated entity (GenerateSnapshotForEntity)
SW->>CTX: Mark entity as deleted using updated ChangeContext
T->>W: Validate entity state (reference, updated part-of-speech, and deletion timestamp)
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
63db780
to
27fc53f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, the slight refactoring of intermediate snapshots has made me even more uncomfortable with it than I already was... not sure what to do about that though.
5105ce7
to
4009ed7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/SIL.Harmony.Tests/DataModelReferenceTests.cs
(1 hunks)src/SIL.Harmony/Changes/ChangeContext.cs
(1 hunks)src/SIL.Harmony/SnapshotWorker.cs
(4 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
src/SIL.Harmony.Tests/DataModelReferenceTests.cs (2)
src/SIL.Harmony.Sample/Models/Word.cs (2)
Guid
(16-25)Word
(5-52)src/SIL.Harmony/DataModel.cs (2)
DataModel
(14-350)DataModel
(31-43)
src/SIL.Harmony/SnapshotWorker.cs (2)
src/SIL.Harmony/Changes/ChangeContext.cs (4)
ChangeContext
(5-29)ChangeContext
(10-17)ValueTask
(23-23)IObjectBase
(28-28)src/SIL.Harmony/Db/ObjectSnapshot.cs (2)
ObjectSnapshot
(32-80)ObjectSnapshot
(34-48)
src/SIL.Harmony/Changes/ChangeContext.cs (4)
src/SIL.Harmony/SnapshotWorker.cs (3)
SnapshotWorker
(11-257)SnapshotWorker
(20-29)SnapshotWorker
(46-50)src/SIL.Harmony/CrdtConfig.cs (2)
CrdtConfig
(12-94)CrdtConfig
(31-37)src/SIL.Harmony/Commit.cs (3)
Commit
(7-41)Commit
(17-21)Commit
(28-31)src/SIL.Harmony/Db/ObjectSnapshot.cs (2)
ObjectSnapshot
(32-80)ObjectSnapshot
(34-48)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build
- GitHub Check: build
- GitHub Check: Analyze (csharp)
🔇 Additional comments (9)
src/SIL.Harmony.Tests/DataModelReferenceTests.cs (2)
88-104
: Well-structured test for reference deletion in a single commitThis test properly validates that when a word and its definition are added and the word is immediately deleted in the same commit, the definition should still exist but be marked as deleted. This directly addresses the PR objective of ensuring reference changes aren't lost during delete operations.
106-128
: Comprehensive test for update and delete operations in a single commitThis test effectively builds on the first test by adding complexity - it confirms that when a definition's part of speech is updated and its parent word is deleted within the same commit, both operations are properly processed. The definition retains its updated part of speech while also being marked as deleted.
src/SIL.Harmony/SnapshotWorker.cs (5)
83-83
: Proper context enrichment for commit processingThe enhanced
ChangeContext
now receives additional parameters, allowing for better state management during commit processing.
101-101
: Improved deletion handling and snapshot generationBy using the expanded context object and the new
GenerateSnapshotForEntity
method, the code now ensures that snapshots created as a result of delete operations are processed with the same logic as regular snapshots.Also applies to: 103-104
116-117
: Updated method signature for better context preservationChanged the
MarkDeleted
method to accept aChangeContext
instead of just aCommit
, allowing it to access the enhanced context information. This enables consistent handling of snapshots during deletion operations.Also applies to: 123-123
132-133
: Consistent snapshot generation and deletion handlingThe consistent use of
GenerateSnapshotForEntity
and passing the full context toMarkDeleted
ensures that recursive deletion operations maintain the same contextual awareness.Also applies to: 137-138
199-226
: Well-encapsulated snapshot generation logicThe extraction of snapshot generation into a dedicated method greatly improves code organization and maintainability. The detailed comments explain the snapshot lifecycle well, and the logic for determining when to create root snapshots and when to preserve intermediate snapshots is clear.
The conditional saving of intermediate snapshots based on commit index parity is an interesting optimization for controlling snapshot frequency.
src/SIL.Harmony/Changes/ChangeContext.cs (2)
5-5
: Appropriate access restriction for internal implementation detailsChanging the class from
public
tointernal
is appropriate as it prevents external code from depending on these implementation details.
10-17
: Enhanced context construction for better state managementThe constructor now accepts additional parameters to support the refactored snapshot generation logic, properly initializing the new properties.
Resolves #30
Instead of dropping snapshots, this PR refactors the SnapshotWorker so that new snapshots triggered by deletes are handled by the same code that handles "normal" snapshots triggered by changes.
In theory we could take it even farther with something like:
private async Task UpdateEntity(Id, Action<Entity, ChangeContext, ...> updater)
which would find the current entity, let the caller do there thing and then generate a new snapshot afterwards, checking whether it was deleted etc.But, it's not quite that simple, so I didn't go for it in this PR.
Summary by CodeRabbit
Tests
Refactor