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

User collection query has limit set to 10 for a single item fetch #7075

Open
vibhor-web-headout opened this issue Jul 9, 2024 · 2 comments
Assignees
Labels

Comments

@vibhor-web-headout
Copy link

vibhor-web-headout commented Jul 9, 2024

Link to reproduction

No response

Describe the Bug

The following is the query passed to the DB adapter from the flow mentioned the file in the following link:

const userQuery = await find({

{"collection":"users","locale":"en","where":{"and":[{"apiKeyIndex":{"equals":"my-api-key-index"}}]},"limit":10,"pagination":true,"page":1}

The limit: 10 causes it to do a full collection scan and later once the query is resolved, payload only refers to the first item in the result.
CMIIW, apiKeyIndex is supposed to be unique for each API-Key, right ?
If so, the limit should be 1

To Reproduce

Any API call with payload-token in its cookie would trigger this flow.

Payload Version

2.22.0

Adapters and Plugins

No response

@vibhor-web-headout vibhor-web-headout added status: needs-triage Possible bug which hasn't been reproduced yet v2 labels Jul 9, 2024
@vibhor-web-headout
Copy link
Author

Another thing to add. apiKeyIndex is not an indexed field per the schema.

During load testing, we observed that the first request takes a decent amount of time (compared to the successive). The query with apiKeyIndex would take longer at first, and the same query later took significantly less time. I guess that the DB cached that query internally.

Have you considered indexing that key since every time authentication makes a query upon that field?

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jul 29, 2024
@jmikrut
Copy link
Member

jmikrut commented Jul 29, 2024

Hey @vibhor-web-headout — good catches. We will index the apiKeyIndex (wow) and also limit the documents to 1. Can also set pagination: false because that's also unnecessary within that find operation.

These changes should be made to v2 and v3.

@jmikrut jmikrut assigned kendelljoseph and unassigned denolfe Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants