@@ -13,6 +13,7 @@ import type { ConversationStats } from "$lib/types/ConversationStats";
13
13
import type { MigrationResult } from "$lib/types/MigrationResult" ;
14
14
import type { Semaphore } from "$lib/types/Semaphore" ;
15
15
import type { AssistantStats } from "$lib/types/AssistantStats" ;
16
+ import { logger } from "$lib/server/logger" ;
16
17
17
18
if ( ! MONGODB_URL ) {
18
19
throw new Error (
@@ -25,7 +26,7 @@ const client = new MongoClient(MONGODB_URL, {
25
26
directConnection : MONGODB_DIRECT_CONNECTION === "true" ,
26
27
} ) ;
27
28
28
- export const connectPromise = client . connect ( ) . catch ( console . error ) ;
29
+ export const connectPromise = client . connect ( ) . catch ( logger . error ) ;
29
30
30
31
export function getCollections ( mongoClient : MongoClient ) {
31
32
const db = mongoClient . db ( MONGODB_DB_NAME + ( import . meta. env . MODE === "test" ? "-test" : "" ) ) ;
@@ -89,25 +90,25 @@ client.on("open", () => {
89
90
{ sessionId : 1 , updatedAt : - 1 } ,
90
91
{ partialFilterExpression : { sessionId : { $exists : true } } }
91
92
)
92
- . catch ( console . error ) ;
93
+ . catch ( logger . error ) ;
93
94
conversations
94
95
. createIndex (
95
96
{ userId : 1 , updatedAt : - 1 } ,
96
97
{ partialFilterExpression : { userId : { $exists : true } } }
97
98
)
98
- . catch ( console . error ) ;
99
+ . catch ( logger . error ) ;
99
100
conversations
100
101
. createIndex (
101
102
{ "message.id" : 1 , "message.ancestors" : 1 } ,
102
103
{ partialFilterExpression : { userId : { $exists : true } } }
103
104
)
104
- . catch ( console . error ) ;
105
+ . catch ( logger . error ) ;
105
106
// To do stats on conversations
106
- conversations . createIndex ( { updatedAt : 1 } ) . catch ( console . error ) ;
107
+ conversations . createIndex ( { updatedAt : 1 } ) . catch ( logger . error ) ;
107
108
// Not strictly necessary, could use _id, but more convenient. Also for stats
108
- conversations . createIndex ( { createdAt : 1 } ) . catch ( console . error ) ;
109
+ conversations . createIndex ( { createdAt : 1 } ) . catch ( logger . error ) ;
109
110
// To do stats on conversation messages
110
- conversations . createIndex ( { "messages.createdAt" : 1 } , { sparse : true } ) . catch ( console . error ) ;
111
+ conversations . createIndex ( { "messages.createdAt" : 1 } , { sparse : true } ) . catch ( logger . error ) ;
111
112
// Unique index for stats
112
113
conversationStats
113
114
. createIndex (
@@ -120,42 +121,42 @@ client.on("open", () => {
120
121
} ,
121
122
{ unique : true }
122
123
)
123
- . catch ( console . error ) ;
124
+ . catch ( logger . error ) ;
124
125
// Allow easy check of last computed stat for given type/dateField
125
126
conversationStats
126
127
. createIndex ( {
127
128
type : 1 ,
128
129
"date.field" : 1 ,
129
130
"date.at" : 1 ,
130
131
} )
131
- . catch ( console . error ) ;
132
- abortedGenerations . createIndex ( { updatedAt : 1 } , { expireAfterSeconds : 30 } ) . catch ( console . error ) ;
133
- abortedGenerations . createIndex ( { conversationId : 1 } , { unique : true } ) . catch ( console . error ) ;
134
- sharedConversations . createIndex ( { hash : 1 } , { unique : true } ) . catch ( console . error ) ;
135
- settings . createIndex ( { sessionId : 1 } , { unique : true , sparse : true } ) . catch ( console . error ) ;
136
- settings . createIndex ( { userId : 1 } , { unique : true , sparse : true } ) . catch ( console . error ) ;
137
- settings . createIndex ( { assistants : 1 } ) . catch ( console . error ) ;
138
- users . createIndex ( { hfUserId : 1 } , { unique : true } ) . catch ( console . error ) ;
139
- users . createIndex ( { sessionId : 1 } , { unique : true , sparse : true } ) . catch ( console . error ) ;
132
+ . catch ( logger . error ) ;
133
+ abortedGenerations . createIndex ( { updatedAt : 1 } , { expireAfterSeconds : 30 } ) . catch ( logger . error ) ;
134
+ abortedGenerations . createIndex ( { conversationId : 1 } , { unique : true } ) . catch ( logger . error ) ;
135
+ sharedConversations . createIndex ( { hash : 1 } , { unique : true } ) . catch ( logger . error ) ;
136
+ settings . createIndex ( { sessionId : 1 } , { unique : true , sparse : true } ) . catch ( logger . error ) ;
137
+ settings . createIndex ( { userId : 1 } , { unique : true , sparse : true } ) . catch ( logger . error ) ;
138
+ settings . createIndex ( { assistants : 1 } ) . catch ( logger . error ) ;
139
+ users . createIndex ( { hfUserId : 1 } , { unique : true } ) . catch ( logger . error ) ;
140
+ users . createIndex ( { sessionId : 1 } , { unique : true , sparse : true } ) . catch ( logger . error ) ;
140
141
// No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
141
- users . createIndex ( { username : 1 } ) . catch ( console . error ) ;
142
- messageEvents . createIndex ( { createdAt : 1 } , { expireAfterSeconds : 60 } ) . catch ( console . error ) ;
143
- sessions . createIndex ( { expiresAt : 1 } , { expireAfterSeconds : 0 } ) . catch ( console . error ) ;
144
- sessions . createIndex ( { sessionId : 1 } , { unique : true } ) . catch ( console . error ) ;
145
- assistants . createIndex ( { createdById : 1 , userCount : - 1 } ) . catch ( console . error ) ;
146
- assistants . createIndex ( { userCount : 1 } ) . catch ( console . error ) ;
147
- assistants . createIndex ( { featured : 1 , userCount : - 1 } ) . catch ( console . error ) ;
148
- assistants . createIndex ( { modelId : 1 , userCount : - 1 } ) . catch ( console . error ) ;
149
- assistants . createIndex ( { searchTokens : 1 } ) . catch ( console . error ) ;
150
- assistants . createIndex ( { last24HoursCount : 1 } ) . catch ( console . error ) ;
142
+ users . createIndex ( { username : 1 } ) . catch ( logger . error ) ;
143
+ messageEvents . createIndex ( { createdAt : 1 } , { expireAfterSeconds : 60 } ) . catch ( logger . error ) ;
144
+ sessions . createIndex ( { expiresAt : 1 } , { expireAfterSeconds : 0 } ) . catch ( logger . error ) ;
145
+ sessions . createIndex ( { sessionId : 1 } , { unique : true } ) . catch ( logger . error ) ;
146
+ assistants . createIndex ( { createdById : 1 , userCount : - 1 } ) . catch ( logger . error ) ;
147
+ assistants . createIndex ( { userCount : 1 } ) . catch ( logger . error ) ;
148
+ assistants . createIndex ( { featured : 1 , userCount : - 1 } ) . catch ( logger . error ) ;
149
+ assistants . createIndex ( { modelId : 1 , userCount : - 1 } ) . catch ( logger . error ) ;
150
+ assistants . createIndex ( { searchTokens : 1 } ) . catch ( logger . error ) ;
151
+ assistants . createIndex ( { last24HoursCount : 1 } ) . catch ( logger . error ) ;
151
152
assistantStats
152
153
// Order of keys is important for the queries
153
154
. createIndex ( { "date.span" : 1 , "date.at" : 1 , assistantId : 1 } , { unique : true } )
154
- . catch ( console . error ) ;
155
- reports . createIndex ( { assistantId : 1 } ) . catch ( console . error ) ;
156
- reports . createIndex ( { createdBy : 1 , assistantId : 1 } ) . catch ( console . error ) ;
155
+ . catch ( logger . error ) ;
156
+ reports . createIndex ( { assistantId : 1 } ) . catch ( logger . error ) ;
157
+ reports . createIndex ( { createdBy : 1 , assistantId : 1 } ) . catch ( logger . error ) ;
157
158
158
159
// Unique index for semaphore and migration results
159
- semaphores . createIndex ( { key : 1 } , { unique : true } ) . catch ( console . error ) ;
160
- semaphores . createIndex ( { createdAt : 1 } , { expireAfterSeconds : 60 } ) . catch ( console . error ) ;
160
+ semaphores . createIndex ( { key : 1 } , { unique : true } ) . catch ( logger . error ) ;
161
+ semaphores . createIndex ( { createdAt : 1 } , { expireAfterSeconds : 60 } ) . catch ( logger . error ) ;
161
162
} ) ;
0 commit comments