KnpLabs / KnpPaginatorBundle

SEO friendly Symfony paginator to sort and paginate
http://knplabs.com/en/blog/knp-paginator-reborn
MIT License
1.76k stars 345 forks source link

how to enable allowDiskUse for Mongodb or how to use Aggregation builder ? #657

Closed shubaivan closed 3 years ago

shubaivan commented 4 years ago

Bug Report

Q A
BC Break yes/no
Bundle version ^5.3@dev
Symfony version 5.0.5
PHP version 7.4.8

when followed for last page with sorting

that's what I used for paginatin

public function getListQuery()
{
    $builder = $this->createQueryBuilder();
    return $builder->getQuery();
}

    $listQuery = $this->documentManager->getRepository(AwinProduct::class)
        ->getListQuery();

    // Paginate the results of the query
    $appointments = $paginator->paginate(
    // Doctrine Query, not results
        $listQuery,
        // Define the page parameter
        $request->query->getInt('page', 1),
        // Items per page
        5
    );

faced with error

CommandException
Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.

how to enable allowDiskUse: true ?

it's possible if using vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php

becuase inside function for execution contain array options public function execute(array $options = [])

it's wotks like that successful

        $builder = $this->createAggregationBuilder();

        $builder->hydrate(false);
        $builder
            ->sort('search_price', 'DESC')
            ->skip(46189)->limit(5);

        $purchase = $builder->execute(['allowDiskUse' => true]);
        return $purchase;

How to reproduce

with big data base, follow to last page with sort like this: ?sort=search_price&direction=desc&page=9239

Expected behavior

successful result

garak commented 4 years ago

It looks like we don't use aggregation builder, so it's currently impossible. If you think that current code can be improved by accepting some new configuration, feel free to propose a PR