mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
sonic: do not block operations
This commit is contained in:
1 parent
69e3ebb7fb
commit
15d26eec37
3 files changed
+7
-4
No files matched your search
@@ -1,8 +1,11 @@
|
|||||||
|
import { Logger } from 'hydrooj/src/logger';
|
||||||
import DomainModel from 'hydrooj/src/model/domain';
|
import DomainModel from 'hydrooj/src/model/domain';
|
||||||
import * as system from 'hydrooj/src/model/system';
|
import * as system from 'hydrooj/src/model/system';
|
||||||
import * as bus from 'hydrooj/src/service/bus';
|
import * as bus from 'hydrooj/src/service/bus';
|
||||||
import sonic from './service';
|
import sonic from './service';
|
||||||
|
|
||||||
|
const logger = new Logger('sonic');
|
||||||
|
|
||||||
bus.on('problem/add', async (doc, docId) => {
|
bus.on('problem/add', async (doc, docId) => {
|
||||||
const union = await DomainModel.searchUnion({ union: doc.domainId, problem: true });
|
const union = await DomainModel.searchUnion({ union: doc.domainId, problem: true });
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
@@ -12,7 +15,7 @@ bus.on('problem/add', async (doc, docId) => {
|
|||||||
sonic.push('problem', `${domainId}@content`, `${doc.domainId}/${docId}`, doc.content.toString()),
|
sonic.push('problem', `${domainId}@content`, `${doc.domainId}/${docId}`, doc.content.toString()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await Promise.all(tasks);
|
Promise.all(tasks).catch((e) => logger.error(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
bus.on('problem/edit', async (pdoc) => {
|
bus.on('problem/edit', async (pdoc) => {
|
||||||
@@ -27,7 +30,7 @@ bus.on('problem/edit', async (pdoc) => {
|
|||||||
.then(() => sonic.push('problem', `${domainId}@content`, id, pdoc.content.toString())),
|
.then(() => sonic.push('problem', `${domainId}@content`, id, pdoc.content.toString())),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await Promise.all(tasks);
|
Promise.all(tasks).catch((e) => logger.error(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
bus.on('problem/del', async (domainId, docId) => {
|
bus.on('problem/del', async (domainId, docId) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/sonic",
|
"name": "@hydrooj/sonic",
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"description": "Sonic search service",
|
"description": "Sonic search service",
|
||||||
"main": "service.js",
|
"main": "service.js",
|
||||||
"typings": "service.d.ts",
|
"typings": "service.d.ts",
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export async function run({ domainId }, report) {
|
|||||||
await Promise.all(tasks).catch((e) => console.log(`${pdoc.domainId}/${pdoc.docId}`, e));
|
await Promise.all(tasks).catch((e) => console.log(`${pdoc.domainId}/${pdoc.docId}`, e));
|
||||||
};
|
};
|
||||||
if (domainId) await iterateAllProblemInDomain(domainId, ['title', 'content'], cb);
|
if (domainId) await iterateAllProblemInDomain(domainId, ['title', 'content'], cb);
|
||||||
else await iterateAllProblem(['title', 'content'], cb);
|
else await iterateAllProblem(['title', 'content', 'tag'], cb);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user