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

Add option to disable count #67

Open
timwangdev opened this issue Jan 17, 2023 · 1 comment
Open

Add option to disable count #67

timwangdev opened this issue Jan 17, 2023 · 1 comment

Comments

@timwangdev
Copy link

timwangdev commented Jan 17, 2023

Counting all rows in a table with a complex query condition could be very slow. If we could disable totalCount output we would save the query execution time.

@timwangdev timwangdev changed the title Add option to disable totalCount Add option to disable count Jan 17, 2023
@timwangdev
Copy link
Author

I'm experimenting with this code snippet, it would have to query the count but still get the hasPreviousPage and hasNextPage info:

    const startCursor = edges.length > 0 ? edges[0].cursor : null;
    const endCursor = edges.length > 0 ? edges[edges.length - 1].cursor : null;

    const prevPaginationQuery = startCursor ? getPaginationQuery(reverseOrder(order), parseCursor(startCursor)) : null;
    const prevPaginationWhere = prevPaginationQuery ? { [Op.and]: [prevPaginationQuery, where] } : where;
    const prevInstance = startCursor && (await modelClass.findOne({ where: prevPaginationWhere, ...restQueryOptions }));

    const nextPaginationQuery = endCursor ? getPaginationQuery(order, parseCursor(endCursor)) : null;
    const nextPaginationWhere = nextPaginationQuery ? { [Op.and]: [nextPaginationQuery, where] } : where;
    const nextInstance = endCursor && (await modelClass.findOne({ where: nextPaginationWhere, ...restQueryOptions }));

    const pageInfo = {
      startCursor,
      endCursor,
      hasPreviousPage: !!prevInstance,
      hasNextPage: !!nextInstance,
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant