Fix/activity durations - #3
Open
tomasvanrijsse wants to merge 43 commits into
Open
Conversation
…ct ticket matching
Wrap the destructive sequence (detach → forceDelete → rebundle) in a database transaction to prevent data loss if bundle() throws mid-operation. Previously, if an error occurred during rebundling, suggestions would already be deleted and activities left with entry_suggestion_id = null, unrecoverable by re-run. Claude
Mocks SuggestionBundler::bundle to throw mid-transaction and asserts the detach/forceDelete work is rolled back, not just the bundle call.
Suggestion and activity IDs were plucked before the transaction opened, so a concurrently queued CreateSuggestion listener could attach an activity to a doomed suggestion after the snapshot but before the detach/forceDelete, orphaning it to the entry_suggestion_id ON DELETE CASCADE. Lock the suggestions with lockForUpdate() and take both snapshots inside the transaction, and detach activities by suggestion ID instead of a pre-plucked activity ID list.
newSuggestionFromActivity() assigned a full Carbon datetime to EntrySuggestion::$date while findMatchingSuggestion() compares against suggestionDateFor()'s toDateString(); the match only worked because MySQL silently truncates the DATE column. Write the same date string that is used for matching, and update the model's @Property annotation for date to ?string to match.
The collapse of a new activity was detected after overlapping activities had already been trimmed and saved, so a fully covered event still shrank its neighbours, the covering activity was re-queried with a looser predicate that matched merely adjacent activities, and the resulting start time depended on database row order. Determine the trimmed start from all dominant overlaps upfront, attach a covered event only to an activity that spans its whole period, and persist trims, the new activity, and absorptions in one transaction.
…t Period model Claude
…suggestions Claude
…al activity creation Claude
…pping periods Replace the buggy `resolveWeightDominance` post-processing step with weight-tier-first group building. Events are now grouped by weight (highest first), chained within each tier, then lower-weight groups are subtracted against already-claimed periods using spatie/period. This fixes the case where a high-weight event fully inside a low-weight event should produce three activities (before, dominant, after) but only produced two because `partition` consumed the spanning event. TimeSlot now extends `Spatie\Period\Period`, replacing hand-rolled `subtract`/`overlaps`/`covers` with Period's `subtract`/`overlapsWith`/ `contains`. Claude
…ojector Chain events directly into Activity objects instead of using an intermediate EventGroup DTO. Inline Period construction replaces the TimeSlot wrapper class. The projector now has two clear phases: chainEvents (grouping) and reduceOverlap (weight-priority splitting and entry trimming in a single pass).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.