core: fix bigint serializer

This commit is contained in:
undefined committed 2021-04-22 22:56:54 +08:00
1 parent f42393f7af
commit b6a6f46d20
5 files changed
+16 -25

No files matched your search

+1 -5
View File
@@ -22,11 +22,7 @@ class MessageModel {
const mdoc = {
from, to, content, _id: res.insertedId, flag,
};
if (from !== to) {
// ENHANCE domainId?
const udoc = await user.getById('system', to);
bus.boardcast('user/message', to, mdoc, udoc);
}
if (from !== to) bus.boardcast('user/message', to, mdoc);
await user.inc(to, 'unreadMsg', 1);
return mdoc;
}
+5 -6
View File
@@ -5,26 +5,25 @@ import db from '../service/db';
const coll = db.collection('opcount');
export async function inc(op: string, ident: string, periodSecs: number, maxOperations: number) {
const curTime = new Date().getTime();
const beginAt = new Date(curTime - (curTime % (periodSecs * 1000)));
const expireAt = new Date(beginAt.getTime() + periodSecs * 1000);
const now = new Date().getTime();
const expireAt = new Date(now - (now % (periodSecs * 1000)) + periodSecs * 1000);
try {
await coll.findOneAndUpdate({
op,
ident,
beginAt,
expireAt,
opcount: { $lt: maxOperations },
}, { $inc: { opcount: 1 } }, { upsert: true });
} catch (e) {
throw new OpcountExceededError(op, periodSecs, maxOperations);
if (e.message.includes('duplicate')) throw new OpcountExceededError(op, periodSecs, maxOperations);
throw e;
}
}
function ensureIndexes() {
return Promise.all([
coll.createIndex('expireAt', { expireAfterSeconds: 0 }),
coll.createIndex({ op: 1, ident: 1 }, { unique: true }),
coll.createIndex({ op: 1, ident: 1, expireAt: 1 }, { unique: true }),
]);
}