nestjsx / nestjs-typeorm-paginate

:page_with_curl: Pagination response object function + types for typeorm + nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Opt-In totalItems Count

JonasLaux opened this issue · comments

Hey,
we're using this plugin for a quite big dataset. Since on every paginate call the totalItems get counted, some of our queries that are also just used internally (so no total pages count needed) are getting quite heave/slow. Is there a way to make the count somehow optional?

Sure we could add that. However I'm not sure it'll make your queries return any quicker if noticable?

Hey,
so when we use the library in the simplest way, it results into 2 Queries. One is the SELECT and one is a count. Let me give you an example:

Implementation:
const result = await paginate<SomeEntity>( this.someRepository, { page: 1, limit: 10, }, { where: { foo: 'bar', }, }, );

Execution results into following Queries:
Select Items
SELECT "SomeEntity"."id" AS "SomeEntity_id", ... FROM "some" "SomeEntity" WHERE "SomeEntity"."foo" = 'bar LIMIT 10;

Count Items
SELECT COUNT(1) AS "cnt" FROM "some" "SomeEntity" WHERE "SomeEntity"."foo" = 'bar;

The second Count query here can take in some situations very long, because it can count on a huge dataset. The result also is for us in most of the times not needed. That's why we think making the second Query optional would give us a huge performance boost.

ahhh yea sorry, I should've thought of that! Sure we can add that! Would you like to add this optional feature? If not let me know and I'll get around to it at some point!

@JonasLaux #610 would you mind giving this a quick review for me?

Looks good, thanks!