stephpy / timeline-bundle

Symfony2 bundle to make timeline
193 stars 57 forks source link

ORM Paginator of getTimeline uses wrong count if actions have multiple components #194

Closed venimus closed 9 years ago

venimus commented 9 years ago

To reproduce create action with 2 components and try to paginate a timeline The paginator Count method will return wrong (bigger) number of results, which will cause the pagination to paginate in more pages than the result set. I tracked the issue to getTimeline method which should not count the results with LEFT JOINS or use DISTINCT.

my code is simple

    $user = $this->getUser();
    $actionManager = $this->get('spy_timeline.action_manager');
    $timelineManager = $this->get('spy_timeline.timeline_manager');
    $subject = $actionManager->findOrCreateComponent($user);
    $timeline = $timelineManager->getTimeline(
        $subject,
        array(
            'context' => $request->get('context', 'GLOBAL'),
            'page' => $request->get('page', 1),
            'max_per_page' => 60,
            'paginate' => true
        )
    );

in most of the actions I have a subject and 2 additional action_components. Doctrine hidrates it properly but count function returns the raw number of results in the query which is actually the number of the action components instead of the actions.

venimus commented 9 years ago

Seems the problem is in https://github.com/stephpy/timeline/blob/master/src/ResultBuilder/Pager/KnpPager.php#L42

where there should be an option distinct => true

$this->pager = $this->paginator->paginate($target, $page, $limit, array('distinct' => true));
venimus commented 9 years ago

fixed in https://github.com/stephpy/timeline/releases/tag/v1.0.4