From 2afd096f87b46a1e6c1de5ba6e77433b63e0c28c Mon Sep 17 00:00:00 2001 From: Eliott C Date: Wed, 14 Feb 2024 10:57:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Create=20index=20on=20u?= =?UTF-8?q?sers.username=20(#819)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🗃️ Create index on `users.username` * 🗃️ Do not do db.assistants.find({modelId: {$exists: true}) since it's always true --- src/lib/server/database.ts | 2 ++ src/routes/assistants/+page.server.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/server/database.ts b/src/lib/server/database.ts index b648d95c8f1..f582ada06d2 100644 --- a/src/lib/server/database.ts +++ b/src/lib/server/database.ts @@ -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); diff --git a/src/routes/assistants/+page.server.ts b/src/routes/assistants/+page.server.ts index 7e190e25579..7d31f1f2cad 100644 --- a/src/routes/assistants/+page.server.ts +++ b/src/routes/assistants/+page.server.ts @@ -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 = { - modelId: modelId ?? { $exists: true }, + ...(modelId && { modelId }), ...(!createdByCurrentUser && { userCount: { $gt: 1 } }), ...(createdByName ? { createdByName } : { featured: true }), };