Skip to content

RelatedActivityLogSource loads all related rows unbounded — N+1 risk #14

@ManukMinasyan

Description

@ManukMinasyan

Summary

RelatedActivityLogSource::resolve() (src/Timeline/Sources/RelatedActivityLogSource.php, line 36) calls $subject->{$relation}()->get() with no limit before querying the activity log. For a subject with thousands of related rows (e.g., a Person with many tasks), this loads every related row into memory just to derive the subject pairs for the activity-log query.

Repro

// Person with 10,000 tasks
$person->timeline()
    ->fromActivityLogOf(['tasks'])
    ->paginate(perPage: 20);
// Loads all 10,000 task rows even though paginator only needs 20 entries

Recommended fix

Add ->limit($window->cap) to the related-row fetch:

$rows = $subject->{$relation}()->limit($window->cap)->get();

The activity-log query is already capped via ->limit($window->cap); the related-row fetch should match.

Tracked by docs spec

Finding C1 in the upcoming docs restructure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions