Skip to content

Commit

Permalink
πŸ—ƒοΈ Create index on users.username (#819)
Browse files Browse the repository at this point in the history
* πŸ—ƒοΈ Create index on `users.username`

* πŸ—ƒοΈ Do not do db.assistants.find({modelId: {$exists: true}) since it's always true
  • Loading branch information
coyotte508 authored Feb 14, 2024
1 parent 450bfce commit 881070b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib/server/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ client.on("open", () => {
settings.createIndex({ assistants: 1 }).catch(console.error);
users.createIndex({ hfUserId: 1 }, { unique: true }).catch(console.error);
users.createIndex({ sessionId: 1 }, { unique: true, sparse: true }).catch(console.error);
// No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
users.createIndex({ username: 1 }).catch(console.error);
messageEvents.createIndex({ createdAt: 1 }, { expireAfterSeconds: 60 }).catch(console.error);
sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 }).catch(console.error);
sessions.createIndex({ sessionId: 1 }, { unique: true }).catch(console.error);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/assistants/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
...(!createdByCurrentUser && { userCount: { $gt: 1 } }),
...(createdByName ? { createdByName } : { featured: true }),
};
Expand Down

0 comments on commit 881070b

Please sign in to comment.