Add opt-in same-save merge for activity timeline (batch_uuid)#32
Merged
Conversation
…ch rows A save touching several custom fields emits one activity row per field, each under the same custom_field_changes key. The previous spread union kept only the last row's value, dropping the rest from the merged entry. Use array_merge so list payloads concatenate while associative maps (native attributes/old) still union per key.
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.
What
Adds an opt-in, read-side "same-save merge" to the activity timeline. When one save produces several activity rows (e.g. a native
updatedrow plus a custom-field row), the consumer can render them as a single timeline entry, keyed by spatie'sbatch_uuid.Why
A single save often emits multiple activity rows. Without merging, each shows as its own timeline entry, fragmenting what is logically one event. This lets consumers collapse them — without changing how activities are written/logged.
Changes
ActivityLogSourcewithSameBatchMerge(?string $mergedRenderer = null).resolve(): when enabled, groups rows viagroupByBatch()and yields onemakeMergedEntry()per group; otherwise unchanged per-row behaviour.groupByBatch(): groups rows sharing a non-emptybatch_uuid, preserving the query's newest-first / first-seen order; rows without abatch_uuideach stay their own group.makeMergedEntry(): representativebase= first row with non-emptyattribute_changes(else first row);properties= union ofextractProperties()across the group;rendererset explicitly soRendererRegistryresolves it before event/type.TimelineBuilder::fromActivityLog(?int $priority = null, ?string $mergedRenderer = null)— passes through to the source only when$mergedRendereris non-null. Defaultnull⇒ existing behaviour.docs/.../1.sources.md(incl. the host-ownedbatch_uuidmigration), README feature bullet, CHANGELOG entry.tests/Feature/SameBatchMergeTest.php— merge carries both payloads + renderer; different/nullbatch_uuidnot merged; newest-first ordering preserved; default behaviour unchanged.Backward compatibility
Fully opt-in. Default
$mergedRenderer = nullkeeps the original per-row behaviour. All 55 existing tests pass.fromActivityLogOf()is not merged yet (follow-up).Consumer requirement
Merge groups by spatie
batch_uuid— the host app owns this column. Ifactivity_loglacks it:Suggested release: minor (v1.2.0).