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

πŸ—ƒοΈ Create index on users.username #819

Merged
merged 2 commits into from
Feb 14, 2024
Merged

Conversation

coyotte508
Copy link
Member

@coyotte508 coyotte508 commented Feb 13, 2024

With 300k users (:exploding_head:) this was a slow query.

Happened on pages like these: https://huggingface.co/chat/assistants?user=julien-c

We may want to link to https://huggingface.co/chat/assistants?userId=xxxx instead, as in some edge cases two users can have the same username. But leaving it up to you for another PR

Note: index is already in prod

@@ -26,7 +26,7 @@ export const load = async ({ url, locals }) => {

// fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
const filter: Filter<Assistant> = {
modelId: modelId ?? { $exists: true },
...(modelId && { modelId }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ternary if possible

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will keep in mind (here both lines below already use this syntax πŸ‘Ό)

Copy link
Collaborator

@nsarrazin nsarrazin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@coyotte508 coyotte508 merged commit 881070b into main Feb 14, 2024
3 checks passed
@coyotte508 coyotte508 deleted the optimize-db-query branch February 14, 2024 09:57
ice91 pushed a commit to ice91/chat-ui that referenced this pull request Oct 30, 2024
* πŸ—ƒοΈ Create index on `users.username`

* πŸ—ƒοΈ Do not do db.assistants.find({modelId: {$exists: true}) since it's always true
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

Successfully merging this pull request may close these issues.

3 participants