🔁 fix: Build the KeyvMongo Key Index Through the Retrying Helper (#17282)

This commit is contained in:
Marco Beretta 2026-10-20 16:17:56 +02:00 • committed by GitHub
parent 14096e7576
commit f5569dff2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,7 @@
import mongoose from 'mongoose';
import { EventEmitter } from 'events';
import { GridFSBucket } from 'mongodb';
import { logger } from '@librechat/data-schemas';
import { buildIndexWithRetry, logger } from '@librechat/data-schemas';
import type { Db, ReadPreference, Collection } from 'mongodb';
interface KeyvMongoOptions {
@ -79,7 +79,10 @@ class KeyvMongoCustom extends EventEmitter {
/** Every read and upsert filters on `key`; unindexed, each one scans the collection.
* Built in the background, and skipped when the deployment disables auto indexing. */
if (mongoose.connection.config?.autoIndex !== false) {
store.createIndex({ key: 1 }).catch((error: unknown) => {
buildIndexWithRetry(
() => store.createIndex({ key: 1 }),
`KeyvMongo "${collection}" key index`,
).catch((error: unknown) => {
logger.warn(`[KeyvMongo] Could not index "${collection}" by key`, error);
});
}