Skip to content

Fix/activity durations - #3

Open
tomasvanrijsse wants to merge 43 commits into
mainfrom
fix/activity-durations
Open

Fix/activity durations#3
tomasvanrijsse wants to merge 43 commits into
mainfrom
fix/activity-durations

Conversation

@tomasvanrijsse

Copy link
Copy Markdown
Contributor

No description provided.

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.
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant