Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting huge number of rows returns an empty array (paginator) #14

Closed
jsayer101 opened this issue Jul 13, 2021 · 5 comments
Closed

Getting huge number of rows returns an empty array (paginator) #14

jsayer101 opened this issue Jul 13, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jsayer101
Copy link
Contributor

Hi !

I'm trying to retrive +50000 rows, as I use this :

            $lines = $rm
                ->createQueryBuilder('purchase.order.line')
                ->select(['id', 'name', 'date_planned', 'order_id', 'product_qty', 'qty_received'])
                ->where($rm->expr()->lt('date_planned', (new DateTime())->format('Y-m-d')))
                ->getQuery()
                ->count();

I get :
50795
But if I use the getResult() function I got an empty array (if I set maxResults to 100, I'll get 100 rows).

I don't know if there is an issue here or if we need to paginate ourselves the requests & responses. It would be great to have a pagination system in the Query Builder if this is the case.

Thanks !

@Ang3 Ang3 added the enhancement New feature or request label Jul 14, 2021
@jsayer101
Copy link
Contributor Author

Resolved using a while loop for myself but that would be a good improvement if the lib could paginate requests itself to retrieve a huge number of rows ! 🥇

$i = 0;
$results = [1];
$lines = [];
while (count($results) !== 0) {
    $results = $rm
        ->createQueryBuilder('purchase.order.line')
        ->search()
        ->select(['id', 'name', 'date_planned', 'order_id', 'product_qty', 'qty_received'])
        ->where($rm->expr()->lt('date_planned', (new DateTime())->format('Y-m-d')))
        ->orderBy('id')
        ->setMaxResults('12000')
        ->setFirstResult($i)
        ->getQuery()
        ->getResult();
    $i += 12000;
    foreach ($results as $result) {
        $lines[] = $result;
    }
}

I'm now getting my +50 000 rows in $lines.

@Ang3
Copy link
Owner

Ang3 commented Jul 15, 2021

Hi, thank your for your feedback. We must know what is the limit for rows (or the time limit maybe).
Do you know the game where we have to find out the price? :P

I'll try to get an answer from Odoo.

@jsayer101
Copy link
Contributor Author

Hi, thank your for your feedback. We must know what is the limit for rows (or the time limit maybe).
Do you know the game where we have to find out the price? :P

I'll try to get an answer from Odoo.

Le Juste Nombre de lignes 😄

I've tried out different requests on different models :

The only thing I know is that it is never the same limit.
I don't think it's a row limit but more a response size limit maybe? When retrieving less fields using "select" you can get more rows in the response.

Are there limits when using XMLRPC ?
Wouldn't it be more convenient to use JSONRPC api from Odoo ?

Hope we can figure this out ! 😃

@Ang3 Ang3 added this to the 7.x milestone Dec 13, 2021
@Ang3 Ang3 self-assigned this Dec 13, 2021
@Ang3
Copy link
Owner

Ang3 commented Dec 13, 2021

Resolved using a while loop for myself but that would be a good improvement if the lib could paginate requests itself to retrieve a huge number of rows ! 🥇

$i = 0;
$results = [1];
$lines = [];
while (count($results) !== 0) {
    $results = $rm
        ->createQueryBuilder('purchase.order.line')
        ->search()
        ->select(['id', 'name', 'date_planned', 'order_id', 'product_qty', 'qty_received'])
        ->where($rm->expr()->lt('date_planned', (new DateTime())->format('Y-m-d')))
        ->orderBy('id')
        ->setMaxResults('12000')
        ->setFirstResult($i)
        ->getQuery()
        ->getResult();
    $i += 12000;
    foreach ($results as $result) {
        $lines[] = $result;
    }
}

I'm now getting my +50 000 rows in $lines.

Nice, a paginator will be implemented. ;)

Three warnings about your query :

  • You called search and select (the search becomes useless)
  • You don't have to format the date (the expression builder makes it for you)
  • The most important: records can change between two requests - I think we should search ID's before, then iterate on it to be sure about data size.

@Ang3 Ang3 changed the title Getting huge number of rows returns an empty array Getting huge number of rows returns an empty array (paginator) Jan 14, 2022
@Ang3 Ang3 modified the milestones: 7.x, 8.x Jan 14, 2022
@Ang3
Copy link
Owner

Ang3 commented Jan 22, 2022

#24

@Ang3 Ang3 closed this as completed Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants