core: fix database text index creation

This commit is contained in:
undefined committed 2021-09-12 05:35:25 +08:00
1 parent f1e2409991
commit bd7cb2e959
2 files changed
+6 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.34.5", "version": "2.34.6",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+5 -5
View File
@@ -61,17 +61,17 @@ class MongoService implements BaseService {
if (!i && Object.keys(index.key).map(k => index.key[k]).includes('text')) { if (!i && Object.keys(index.key).map(k => index.key[k]).includes('text')) {
i = existed.find(t => t.textIndexVersion); i = existed.find(t => t.textIndexVersion);
} }
index.background = true;
if (!i) {
logger.info('Indexing %s.%s with key %o', coll.collectionName, index.name, index.key);
await coll.createIndexes([index]);
} else if (i.v < 2 || i.name !== index.name || JSON.stringify(i.key) !== JSON.stringify(index.key)) {
if (i.textIndexVersion) { if (i.textIndexVersion) {
const cur = Object.keys(i.key).filter(t => !t.startsWith('_')).map(k => k + ':' + i.key[k]); const cur = Object.keys(i.key).filter(t => !t.startsWith('_')).map(k => k + ':' + i.key[k]);
for (const key of Object.keys(i.weights)) cur.push(key + ':text'); for (const key of Object.keys(i.weights)) cur.push(key + ':text');
const wanted = Object.keys(index.key).map(key => key + ':' + index.key[key]); const wanted = Object.keys(index.key).map(key => key + ':' + index.key[key]);
if (cur.sort().join(' ') === wanted.sort().join(' ') && i.name === index.name) continue; if (cur.sort().join(' ') === wanted.sort().join(' ') && i.name === index.name) continue;
} }
index.background = true;
if (!i) {
logger.info('Indexing %s.%s with key %o', coll.collectionName, index.name, index.key);
await coll.createIndexes([index]);
} else if (i.v < 2 || i.name !== index.name || JSON.stringify(i.key) !== JSON.stringify(index.key)) {
logger.info('Re-Index %s.%s with key %o', coll.collectionName, index.name, index.key); logger.info('Re-Index %s.%s with key %o', coll.collectionName, index.name, index.key);
await coll.dropIndex(i.name); await coll.dropIndex(i.name);
await coll.createIndexes([index]); await coll.createIndexes([index]);