Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Fix context of logger (#1112)
Browse files* fix this context of logger
* lint
---------
Co-authored-by: Nathan Sarrazin <[email protected]>
src/lib/server/database.ts
CHANGED
@@ -133,22 +133,24 @@ export class Database {
|
|
133 |
{ sessionId: 1, updatedAt: -1 },
|
134 |
{ partialFilterExpression: { sessionId: { $exists: true } } }
|
135 |
)
|
136 |
-
.catch(logger.error);
|
137 |
conversations
|
138 |
.createIndex(
|
139 |
{ userId: 1, updatedAt: -1 },
|
140 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
141 |
)
|
142 |
-
.catch(logger.error);
|
143 |
conversations
|
144 |
.createIndex(
|
145 |
{ "message.id": 1, "message.ancestors": 1 },
|
146 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
147 |
)
|
148 |
-
.catch(logger.error);
|
149 |
// Not strictly necessary, could use _id, but more convenient. Also for stats
|
150 |
// To do stats on conversation messages
|
151 |
-
conversations
|
|
|
|
|
152 |
// Unique index for stats
|
153 |
conversationStats
|
154 |
.createIndex(
|
@@ -161,7 +163,7 @@ export class Database {
|
|
161 |
},
|
162 |
{ unique: true }
|
163 |
)
|
164 |
-
.catch(logger.error);
|
165 |
// Allow easy check of last computed stat for given type/dateField
|
166 |
conversationStats
|
167 |
.createIndex({
|
@@ -169,38 +171,50 @@ export class Database {
|
|
169 |
"date.field": 1,
|
170 |
"date.at": 1,
|
171 |
})
|
172 |
-
.catch(logger.error);
|
173 |
abortedGenerations
|
174 |
.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 })
|
175 |
-
.catch(logger.error);
|
176 |
-
abortedGenerations
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
settings
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
// No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
|
184 |
-
users.createIndex({ username: 1 }).catch(logger.error);
|
185 |
-
messageEvents
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
assistants.createIndex({
|
191 |
-
assistants.createIndex({
|
192 |
-
assistants.createIndex({
|
193 |
-
assistants.createIndex({
|
|
|
|
|
194 |
assistantStats
|
195 |
// Order of keys is important for the queries
|
196 |
.createIndex({ "date.span": 1, "date.at": 1, assistantId: 1 }, { unique: true })
|
197 |
-
.catch(logger.error);
|
198 |
-
reports.createIndex({ assistantId: 1 }).catch(logger.error);
|
199 |
-
reports.createIndex({ createdBy: 1, assistantId: 1 }).catch(logger.error);
|
200 |
|
201 |
// Unique index for semaphore and migration results
|
202 |
-
semaphores.createIndex({ key: 1 }, { unique: true }).catch(logger.error);
|
203 |
-
semaphores
|
|
|
|
|
204 |
}
|
205 |
}
|
206 |
|
|
|
133 |
{ sessionId: 1, updatedAt: -1 },
|
134 |
{ partialFilterExpression: { sessionId: { $exists: true } } }
|
135 |
)
|
136 |
+
.catch((e) => logger.error(e));
|
137 |
conversations
|
138 |
.createIndex(
|
139 |
{ userId: 1, updatedAt: -1 },
|
140 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
141 |
)
|
142 |
+
.catch((e) => logger.error(e));
|
143 |
conversations
|
144 |
.createIndex(
|
145 |
{ "message.id": 1, "message.ancestors": 1 },
|
146 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
147 |
)
|
148 |
+
.catch((e) => logger.error(e));
|
149 |
// Not strictly necessary, could use _id, but more convenient. Also for stats
|
150 |
// To do stats on conversation messages
|
151 |
+
conversations
|
152 |
+
.createIndex({ "messages.createdAt": 1 }, { sparse: true })
|
153 |
+
.catch((e) => logger.error(e));
|
154 |
// Unique index for stats
|
155 |
conversationStats
|
156 |
.createIndex(
|
|
|
163 |
},
|
164 |
{ unique: true }
|
165 |
)
|
166 |
+
.catch((e) => logger.error(e));
|
167 |
// Allow easy check of last computed stat for given type/dateField
|
168 |
conversationStats
|
169 |
.createIndex({
|
|
|
171 |
"date.field": 1,
|
172 |
"date.at": 1,
|
173 |
})
|
174 |
+
.catch((e) => logger.error(e));
|
175 |
abortedGenerations
|
176 |
.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 })
|
177 |
+
.catch((e) => logger.error(e));
|
178 |
+
abortedGenerations
|
179 |
+
.createIndex({ conversationId: 1 }, { unique: true })
|
180 |
+
.catch((e) => logger.error(e));
|
181 |
+
sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch((e) => logger.error(e));
|
182 |
+
settings
|
183 |
+
.createIndex({ sessionId: 1 }, { unique: true, sparse: true })
|
184 |
+
.catch((e) => logger.error(e));
|
185 |
+
settings
|
186 |
+
.createIndex({ userId: 1 }, { unique: true, sparse: true })
|
187 |
+
.catch((e) => logger.error(e));
|
188 |
+
settings.createIndex({ assistants: 1 }).catch((e) => logger.error(e));
|
189 |
+
users.createIndex({ hfUserId: 1 }, { unique: true }).catch((e) => logger.error(e));
|
190 |
+
users
|
191 |
+
.createIndex({ sessionId: 1 }, { unique: true, sparse: true })
|
192 |
+
.catch((e) => logger.error(e));
|
193 |
// No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
|
194 |
+
users.createIndex({ username: 1 }).catch((e) => logger.error(e));
|
195 |
+
messageEvents
|
196 |
+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: 60 })
|
197 |
+
.catch((e) => logger.error(e));
|
198 |
+
sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 }).catch((e) => logger.error(e));
|
199 |
+
sessions.createIndex({ sessionId: 1 }, { unique: true }).catch((e) => logger.error(e));
|
200 |
+
assistants.createIndex({ createdById: 1, userCount: -1 }).catch((e) => logger.error(e));
|
201 |
+
assistants.createIndex({ userCount: 1 }).catch((e) => logger.error(e));
|
202 |
+
assistants.createIndex({ featured: 1, userCount: -1 }).catch((e) => logger.error(e));
|
203 |
+
assistants.createIndex({ modelId: 1, userCount: -1 }).catch((e) => logger.error(e));
|
204 |
+
assistants.createIndex({ searchTokens: 1 }).catch((e) => logger.error(e));
|
205 |
+
assistants.createIndex({ last24HoursCount: 1 }).catch((e) => logger.error(e));
|
206 |
assistantStats
|
207 |
// Order of keys is important for the queries
|
208 |
.createIndex({ "date.span": 1, "date.at": 1, assistantId: 1 }, { unique: true })
|
209 |
+
.catch((e) => logger.error(e));
|
210 |
+
reports.createIndex({ assistantId: 1 }).catch((e) => logger.error(e));
|
211 |
+
reports.createIndex({ createdBy: 1, assistantId: 1 }).catch((e) => logger.error(e));
|
212 |
|
213 |
// Unique index for semaphore and migration results
|
214 |
+
semaphores.createIndex({ key: 1 }, { unique: true }).catch((e) => logger.error(e));
|
215 |
+
semaphores
|
216 |
+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: 60 })
|
217 |
+
.catch((e) => logger.error(e));
|
218 |
}
|
219 |
}
|
220 |
|
src/routes/admin/stats/compute/+server.ts
CHANGED
@@ -8,9 +8,13 @@ import { logger } from "$lib/server/logger";
|
|
8 |
|
9 |
export async function POST() {
|
10 |
for (const span of ["day", "week", "month"] as const) {
|
11 |
-
computeStats({ dateField: "updatedAt", type: "conversation", span }).catch(
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
|
16 |
return json({}, { status: 202 });
|
|
|
8 |
|
9 |
export async function POST() {
|
10 |
for (const span of ["day", "week", "month"] as const) {
|
11 |
+
computeStats({ dateField: "updatedAt", type: "conversation", span }).catch((e) =>
|
12 |
+
logger.error(e)
|
13 |
+
);
|
14 |
+
computeStats({ dateField: "createdAt", type: "conversation", span }).catch((e) =>
|
15 |
+
logger.error(e)
|
16 |
+
);
|
17 |
+
computeStats({ dateField: "createdAt", type: "message", span }).catch((e) => logger.error(e));
|
18 |
}
|
19 |
|
20 |
return json({}, { status: 202 });
|