@@ -72,7 +72,7 @@ export class Database {
7272 this . client . db ( config . MONGODB_DB_NAME + ( import . meta. env . MODE === "test" ? "-test" : "" ) ) ;
7373 await this . initDatabase ( ) ;
7474 } catch ( err ) {
75- logger . error ( err , "Connection error " ) ;
75+ logger . error ( err , "Error connecting to database " ) ;
7676 process . exit ( 1 ) ;
7777 }
7878
@@ -182,24 +182,32 @@ export class Database {
182182 { sessionId : 1 , updatedAt : - 1 } ,
183183 { partialFilterExpression : { sessionId : { $exists : true } } }
184184 )
185- . catch ( ( e ) => logger . error ( e ) ) ;
185+ . catch ( ( e ) =>
186+ logger . error ( e , "Error creating index for conversations by sessionId and updatedAt" )
187+ ) ;
186188 conversations
187189 . createIndex (
188190 { userId : 1 , updatedAt : - 1 } ,
189191 { partialFilterExpression : { userId : { $exists : true } } }
190192 )
191- . catch ( ( e ) => logger . error ( e ) ) ;
193+ . catch ( ( e ) =>
194+ logger . error ( e , "Error creating index for conversations by userId and updatedAt" )
195+ ) ;
192196 conversations
193197 . createIndex (
194198 { "message.id" : 1 , "message.ancestors" : 1 } ,
195199 { partialFilterExpression : { userId : { $exists : true } } }
196200 )
197- . catch ( ( e ) => logger . error ( e ) ) ;
201+ . catch ( ( e ) =>
202+ logger . error ( e , "Error creating index for conversations by messageId and ancestors" )
203+ ) ;
198204 // Not strictly necessary, could use _id, but more convenient. Also for stats
199205 // To do stats on conversation messages
200206 conversations
201207 . createIndex ( { "messages.createdAt" : 1 } , { sparse : true } )
202- . catch ( ( e ) => logger . error ( e ) ) ;
208+ . catch ( ( e ) =>
209+ logger . error ( e , "Error creating index for conversations by messages createdAt" )
210+ ) ;
203211 // Unique index for stats
204212 conversationStats
205213 . createIndex (
@@ -212,82 +220,139 @@ export class Database {
212220 } ,
213221 { unique : true }
214222 )
215- . catch ( ( e ) => logger . error ( e ) ) ;
223+ . catch ( ( e ) =>
224+ logger . error (
225+ e ,
226+ "Error creating index for conversationStats by type, date.field and date.span"
227+ )
228+ ) ;
216229 // Allow easy check of last computed stat for given type/dateField
217230 conversationStats
218231 . createIndex ( {
219232 type : 1 ,
220233 "date.field" : 1 ,
221234 "date.at" : 1 ,
222235 } )
223- . catch ( ( e ) => logger . error ( e ) ) ;
236+ . catch ( ( e ) => logger . error ( e , "Error creating index for abortedGenerations by updatedAt" ) ) ;
224237 abortedGenerations
225238 . createIndex ( { updatedAt : 1 } , { expireAfterSeconds : 30 } )
226- . catch ( ( e ) => logger . error ( e ) ) ;
239+ . catch ( ( e ) =>
240+ logger . error (
241+ e ,
242+ "Error creating index for abortedGenerations by updatedAt and expireAfterSeconds"
243+ )
244+ ) ;
227245 abortedGenerations
228246 . createIndex ( { conversationId : 1 } , { unique : true } )
229- . catch ( ( e ) => logger . error ( e ) ) ;
247+ . catch ( ( e ) =>
248+ logger . error ( e , "Error creating index for abortedGenerations by conversationId" )
249+ ) ;
230250 sharedConversations . createIndex ( { hash : 1 } , { unique : true } ) . catch ( ( e ) => logger . error ( e ) ) ;
231251 settings
232252 . createIndex ( { sessionId : 1 } , { unique : true , sparse : true } )
233- . catch ( ( e ) => logger . error ( e ) ) ;
253+ . catch ( ( e ) => logger . error ( e , "Error creating index for settings by sessionId" ) ) ;
234254 settings
235255 . createIndex ( { userId : 1 } , { unique : true , sparse : true } )
236- . catch ( ( e ) => logger . error ( e ) ) ;
237- settings . createIndex ( { assistants : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
238- users . createIndex ( { hfUserId : 1 } , { unique : true } ) . catch ( ( e ) => logger . error ( e ) ) ;
256+ . catch ( ( e ) => logger . error ( e , "Error creating index for settings by userId" ) ) ;
257+ settings
258+ . createIndex ( { assistants : 1 } )
259+ . catch ( ( e ) => logger . error ( e , "Error creating index for settings by assistants" ) ) ;
260+ users
261+ . createIndex ( { hfUserId : 1 } , { unique : true } )
262+ . catch ( ( e ) => logger . error ( e , "Error creating index for users by hfUserId" ) ) ;
239263 users
240264 . createIndex ( { sessionId : 1 } , { unique : true , sparse : true } )
241- . catch ( ( e ) => logger . error ( e ) ) ;
265+ . catch ( ( e ) => logger . error ( e , "Error creating index for users by sessionId" ) ) ;
242266 // No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
243- users . createIndex ( { username : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
267+ users
268+ . createIndex ( { username : 1 } )
269+ . catch ( ( e ) => logger . error ( e , "Error creating index for users by username" ) ) ;
244270 messageEvents
245271 . createIndex ( { expiresAt : 1 } , { expireAfterSeconds : 1 } )
246- . catch ( ( e ) => logger . error ( e ) ) ;
272+ . catch ( ( e ) => logger . error ( e , "Error creating index for messageEvents by expiresAt" ) ) ;
247273 sessions . createIndex ( { expiresAt : 1 } , { expireAfterSeconds : 0 } ) . catch ( ( e ) => logger . error ( e ) ) ;
248- sessions . createIndex ( { sessionId : 1 } , { unique : true } ) . catch ( ( e ) => logger . error ( e ) ) ;
249- assistants . createIndex ( { createdById : 1 , userCount : - 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
250- assistants . createIndex ( { userCount : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
251- assistants . createIndex ( { review : 1 , userCount : - 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
252- assistants . createIndex ( { modelId : 1 , userCount : - 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
253- assistants . createIndex ( { searchTokens : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
254- assistants . createIndex ( { last24HoursCount : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
274+ sessions
275+ . createIndex ( { sessionId : 1 } , { unique : true } )
276+ . catch ( ( e ) => logger . error ( e , "Error creating index for sessions by sessionId" ) ) ;
277+ assistants
278+ . createIndex ( { createdById : 1 , userCount : - 1 } )
279+ . catch ( ( e ) =>
280+ logger . error ( e , "Error creating index for assistants by createdById and userCount" )
281+ ) ;
282+ assistants
283+ . createIndex ( { userCount : 1 } )
284+ . catch ( ( e ) => logger . error ( e , "Error creating index for assistants by userCount" ) ) ;
285+ assistants
286+ . createIndex ( { review : 1 , userCount : - 1 } )
287+ . catch ( ( e ) => logger . error ( e , "Error creating index for assistants by review and userCount" ) ) ;
288+ assistants
289+ . createIndex ( { modelId : 1 , userCount : - 1 } )
290+ . catch ( ( e ) =>
291+ logger . error ( e , "Error creating index for assistants by modelId and userCount" )
292+ ) ;
293+ assistants
294+ . createIndex ( { searchTokens : 1 } )
295+ . catch ( ( e ) => logger . error ( e , "Error creating index for assistants by searchTokens" ) ) ;
296+ assistants
297+ . createIndex ( { last24HoursCount : 1 } )
298+ . catch ( ( e ) => logger . error ( e , "Error creating index for assistants by last24HoursCount" ) ) ;
255299 assistants
256300 . createIndex ( { last24HoursUseCount : - 1 , useCount : - 1 , _id : 1 } )
257- . catch ( ( e ) => logger . error ( e ) ) ;
301+ . catch ( ( e ) =>
302+ logger . error ( e , "Error creating index for assistants by last24HoursUseCount and useCount" )
303+ ) ;
258304 assistantStats
259305 // Order of keys is important for the queries
260306 . createIndex ( { "date.span" : 1 , "date.at" : 1 , assistantId : 1 } , { unique : true } )
261- . catch ( ( e ) => logger . error ( e ) ) ;
262- reports . createIndex ( { assistantId : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
263- reports . createIndex ( { createdBy : 1 , assistantId : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
307+ . catch ( ( e ) =>
308+ logger . error (
309+ e ,
310+ "Error creating index for assistantStats by date.span and date.at and assistantId"
311+ )
312+ ) ;
313+ reports
314+ . createIndex ( { assistantId : 1 } )
315+ . catch ( ( e ) => logger . error ( e , "Error creating index for reports by assistantId" ) ) ;
316+ reports
317+ . createIndex ( { createdBy : 1 , assistantId : 1 } )
318+ . catch ( ( e ) =>
319+ logger . error ( e , "Error creating index for reports by createdBy and assistantId" )
320+ ) ;
264321
265322 // Unique index for semaphore and migration results
266323 semaphores . createIndex ( { key : 1 } , { unique : true } ) . catch ( ( e ) => logger . error ( e ) ) ;
267324 semaphores
268325 . createIndex ( { deleteAt : 1 } , { expireAfterSeconds : 1 } )
269- . catch ( ( e ) => logger . error ( e ) ) ;
326+ . catch ( ( e ) => logger . error ( e , "Error creating index for semaphores by deleteAt" ) ) ;
270327 tokenCaches
271328 . createIndex ( { createdAt : 1 } , { expireAfterSeconds : 5 * 60 } )
272- . catch ( ( e ) => logger . error ( e ) ) ;
273- tokenCaches . createIndex ( { tokenHash : 1 } ) . catch ( ( e ) => logger . error ( e ) ) ;
329+ . catch ( ( e ) => logger . error ( e , "Error creating index for tokenCaches by createdAt" ) ) ;
330+ tokenCaches
331+ . createIndex ( { tokenHash : 1 } )
332+ . catch ( ( e ) => logger . error ( e , "Error creating index for tokenCaches by tokenHash" ) ) ;
274333 // Tools removed: skipping tools indexes
275334
276335 conversations
277336 . createIndex ( {
278337 "messages.from" : 1 ,
279338 createdAt : 1 ,
280339 } )
281- . catch ( ( e ) => logger . error ( e ) ) ;
340+ . catch ( ( e ) =>
341+ logger . error ( e , "Error creating index for conversations by messages from and createdAt" )
342+ ) ;
282343
283344 conversations
284345 . createIndex ( {
285346 userId : 1 ,
286347 sessionId : 1 ,
287348 } )
288- . catch ( ( e ) => logger . error ( e ) ) ;
349+ . catch ( ( e ) =>
350+ logger . error ( e , "Error creating index for conversations by userId and sessionId" )
351+ ) ;
289352
290- config . createIndex ( { key : 1 } , { unique : true } ) . catch ( ( e ) => logger . error ( e ) ) ;
353+ config
354+ . createIndex ( { key : 1 } , { unique : true } )
355+ . catch ( ( e ) => logger . error ( e , "Error creating index for config by key" ) ) ;
291356 }
292357}
293358
0 commit comments