core: use mongodb@6

This commit is contained in:
undefined committed 2025-03-21 06:28:56 +08:00
1 parent 0bd15caee6
commit b6f1a9c627
17 files changed
+64 -80

No files matched your search

+2 -2
View File
@@ -41,9 +41,9 @@
"lru-cache": "^10.4.3", "lru-cache": "^10.4.3",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"moment-timezone": "^0.5.47", "moment-timezone": "^0.5.47",
"mongodb": "^5.9.2", "mongodb": "^6.15.0",
"mongodb-uri": "^0.9.7", "mongodb-uri": "^0.9.7",
"nanoid": "^5.1.4", "nanoid": "^5.1.5",
"nodemailer": "^6.10.0", "nodemailer": "^6.10.0",
"notp": "^2.0.3", "notp": "^2.0.3",
"p-queue": "^8.1.0", "p-queue": "^8.1.0",
+1 -2
View File
@@ -13,12 +13,11 @@ class BlackListModel {
else if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate(); else if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate();
else if (expire instanceof Date) expireAt = expire; else if (expire instanceof Date) expireAt = expire;
else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000); else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ _id: id }, { _id: id },
{ $set: { expireAt } }, { $set: { expireAt } },
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
return res.value;
} }
@ArgMethod @ArgMethod
+15 -28
View File
@@ -109,12 +109,11 @@ export async function set<K extends keyof DocType>(
if ($set) update.$set = $set; if ($set) update.$set = $set;
if ($unset) update.$unset = $unset; if ($unset) update.$unset = $unset;
if ($push) update.$push = $push; if ($push) update.$push = $push;
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
update, update,
{ returnDocument: 'after', upsert: true }, { returnDocument: 'after', upsert: true },
); );
return res.value;
} }
export function deleteOne<K extends keyof DocType>( export function deleteOne<K extends keyof DocType>(
@@ -150,24 +149,22 @@ export async function inc<K extends keyof DocType>(
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
key: NumberKeys<DocType[K]>, value: number, key: NumberKeys<DocType[K]>, value: number,
) { ) {
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
{ $inc: { [key]: value } }, { $inc: { [key]: value } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value;
} }
export async function incAndSet<K extends keyof DocType>( export async function incAndSet<K extends keyof DocType>(
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
key: NumberKeys<DocType[K]>, value: number, args: Partial<DocType[K]>, key: NumberKeys<DocType[K]>, value: number, args: Partial<DocType[K]>,
) { ) {
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
{ $inc: { [key]: value }, $set: args }, { $inc: { [key]: value }, $set: args },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value;
} }
export function count<K extends keyof DocType>( export function count<K extends keyof DocType>(
@@ -211,13 +208,12 @@ export async function pull<K extends keyof DocType, T extends ArrayKeys<DocType[
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
setKey: T, contents: Filter<DocType[K][T][0]>, setKey: T, contents: Filter<DocType[K][T][0]>,
): Promise<DocType[K]> { ): Promise<DocType[K]> {
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
// @ts-ignore // @ts-ignore
{ $pull: { [setKey]: { $in: contents } } }, { $pull: { [setKey]: { $in: contents } } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value;
} }
export async function deleteSub<T extends keyof DocType, K extends ArrayKeys<DocType[T]>>( export async function deleteSub<T extends keyof DocType, K extends ArrayKeys<DocType[T]>>(
@@ -225,13 +221,12 @@ export async function deleteSub<T extends keyof DocType, K extends ArrayKeys<Doc
key: K, subId: MaybeArray<DocType[T][K][0]['_id']>, key: K, subId: MaybeArray<DocType[T][K][0]['_id']>,
): Promise<DocType[T]> { ): Promise<DocType[T]> {
subId = (subId instanceof Array) ? subId : [subId]; subId = (subId instanceof Array) ? subId : [subId];
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
// @ts-ignore // @ts-ignore
{ $pull: { [key]: { _id: { $in: subId } } } }, { $pull: { [key]: { _id: { $in: subId } } } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value;
} }
export async function getSub<T extends keyof DocType, K extends ArrayKeys<DocType[T]>>( export async function getSub<T extends keyof DocType, K extends ArrayKeys<DocType[T]>>(
@@ -257,7 +252,7 @@ export async function setSub<T extends keyof DocType, K extends NormalArrayKeys<
): Promise<DocType[T]> { ): Promise<DocType[T]> {
const $set: Record<string, any> = {}; const $set: Record<string, any> = {};
for (const k in args) $set[`${key}.$.${k}`] = args[k]; for (const k in args) $set[`${key}.$.${k}`] = args[k];
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ {
domainId, domainId,
docType, docType,
@@ -267,20 +262,18 @@ export async function setSub<T extends keyof DocType, K extends NormalArrayKeys<
{ $set }, { $set },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value;
} }
export async function addToSet<T extends keyof DocType, K extends ArrayKeys<DocType[T], string>>( export async function addToSet<T extends keyof DocType, K extends ArrayKeys<DocType[T], string>>(
domainId: string, docType: T, docId: DocType[T]['docId'], domainId: string, docType: T, docId: DocType[T]['docId'],
setKey: K, content: string, setKey: K, content: string,
) { ) {
const res = await coll.findOneAndUpdate( return await coll.findOneAndUpdate(
{ domainId, docType, docId }, { domainId, docType, docId },
// @ts-ignore // @ts-ignore
{ $addToSet: { [setKey]: content } }, { $addToSet: { [setKey]: content } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value;
} }
export async function getStatus<K extends keyof DocStatusType>( export async function getStatus<K extends keyof DocStatusType>(
@@ -305,7 +298,7 @@ export async function setStatus<K extends keyof DocStatusType>(
domainId: string, docType: K, docId: DocStatusType[K]['docId'], uid: number, domainId: string, docType: K, docId: DocStatusType[K]['docId'], uid: number,
args: UpdateFilter<DocStatusType[K]>['$set'], returnDocument: 'before' | 'after' = 'after', args: UpdateFilter<DocStatusType[K]>['$set'], returnDocument: 'before' | 'after' = 'after',
): Promise<DocStatusType[K]> { ): Promise<DocStatusType[K]> {
const res = await collStatus.findOneAndUpdate( return await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid }, { domainId, docType, docId, uid },
{ $set: args, $inc: { counter: 1 } }, { $set: args, $inc: { counter: 1 } },
{ {
@@ -315,7 +308,6 @@ export async function setStatus<K extends keyof DocStatusType>(
...(returnDocument === 'before' ? { readConcern: { level: 'majority' }, readPreference: 'primary' } : {}), ...(returnDocument === 'before' ? { readConcern: { level: 'majority' }, readPreference: 'primary' } : {}),
}, },
); );
return res.value;
} }
export async function setMultiStatus<K extends keyof DocStatusType>( export async function setMultiStatus<K extends keyof DocStatusType>(
@@ -333,12 +325,11 @@ export async function setStatusIfNotCondition<T extends keyof DocStatusType>(
returnDocument: 'before' | 'after' = 'after', returnDocument: 'before' | 'after' = 'after',
): Promise<DocStatusType[T]> { ): Promise<DocStatusType[T]> {
try { try {
const res = await collStatus.findOneAndUpdate( return await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid, $nor: [filter] }, { domainId, docType, docId, uid, $nor: [filter] },
{ $set: args }, { $set: args },
{ upsert: true, returnDocument }, { upsert: true, returnDocument },
); );
return res.value;
} catch (e) { } catch (e) {
return false; return false;
} }
@@ -364,24 +355,22 @@ export async function cappedIncStatus<T extends keyof DocStatusType>(
const $not = value > 0 ? { $gte: maxValue } : { $lte: minValue }; const $not = value > 0 ? { $gte: maxValue } : { $lte: minValue };
const operation = { $inc: { [key]: value } } as UpdateFilter<DocStatusType[T]>; const operation = { $inc: { [key]: value } } as UpdateFilter<DocStatusType[T]>;
if (Object.keys(setPayload).length) operation.$set = setPayload; if (Object.keys(setPayload).length) operation.$set = setPayload;
const res = await collStatus.findOneAndUpdate( return await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid, [key]: { $not } }, { domainId, docType, docId, uid, [key]: { $not } },
operation, operation,
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
return res.value;
} }
export async function incStatus<T extends keyof DocStatusType>( export async function incStatus<T extends keyof DocStatusType>(
domainId: string, docType: T, docId: DocStatusType[T]['docId'], uid: number, domainId: string, docType: T, docId: DocStatusType[T]['docId'], uid: number,
key: NumberKeys<DocStatusType[T]>, value: number, key: NumberKeys<DocStatusType[T]>, value: number,
): Promise<DocStatusType[T]> { ): Promise<DocStatusType[T]> {
const res = await collStatus.findOneAndUpdate( return await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid }, { domainId, docType, docId, uid },
{ $inc: { [key]: value } }, { $inc: { [key]: value } },
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
return res.value;
} }
export async function revPushStatus<T extends keyof DocStatusType>( export async function revPushStatus<T extends keyof DocStatusType>(
@@ -393,7 +382,7 @@ export async function revPushStatus<T extends keyof DocStatusType>(
{ $set: { [`${key}.$`]: value }, $inc: { rev: 1 } }, { $set: { [`${key}.$`]: value }, $inc: { rev: 1 } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
if (!res.value) { if (!res) {
res = await collStatus.findOneAndUpdate( res = await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid }, { domainId, docType, docId, uid },
// @ts-ignore // @ts-ignore
@@ -401,18 +390,17 @@ export async function revPushStatus<T extends keyof DocStatusType>(
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
} }
return res.value; return res;
} }
export async function revInitStatus<T extends keyof DocStatusType>( export async function revInitStatus<T extends keyof DocStatusType>(
domainId: string, docType: T, docId: DocStatusType[T]['docId'], uid: number, domainId: string, docType: T, docId: DocStatusType[T]['docId'], uid: number,
): Promise<DocStatusType[T]> { ): Promise<DocStatusType[T]> {
const res = await collStatus.findOneAndUpdate( return await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid }, { domainId, docType, docId, uid },
{ $inc: { rev: 1 } }, { $inc: { rev: 1 } },
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
return res.value;
} }
export async function revSetStatus<T extends keyof DocStatusType>( export async function revSetStatus<T extends keyof DocStatusType>(
@@ -421,8 +409,7 @@ export async function revSetStatus<T extends keyof DocStatusType>(
): Promise<any> { ): Promise<any> {
const filter = { domainId, docType, docId, uid, rev }; const filter = { domainId, docType, docId, uid, rev };
const update = { $set: args, $inc: { rev: 1 } }; const update = { $set: args, $inc: { rev: 1 } };
const res = await collStatus.findOneAndUpdate(filter, update, { returnDocument: 'after' }); return await collStatus.findOneAndUpdate(filter, update, { returnDocument: 'after' });
return res.value;
} }
export async function apply(ctx: Context) { export async function apply(ctx: Context) {
+6 -6
View File
@@ -101,23 +101,23 @@ class DomainModel {
domainId = domainId.toLowerCase(); domainId = domainId.toLowerCase();
await bus.parallel('domain/before-update', domainId, $set); await bus.parallel('domain/before-update', domainId, $set);
const result = await coll.findOneAndUpdate({ lower: domainId }, { $set }, { returnDocument: 'after' }); const result = await coll.findOneAndUpdate({ lower: domainId }, { $set }, { returnDocument: 'after' });
if (result.value) { if (result) {
await bus.parallel('domain/update', domainId, $set, result.value); await bus.parallel('domain/update', domainId, $set, result);
bus.broadcast('domain/delete-cache', domainId); bus.broadcast('domain/delete-cache', domainId);
} }
return result.value; return result;
} }
@ArgMethod @ArgMethod
static async inc(domainId: string, field: NumberKeys<DomainDoc>, n: number): Promise<number | null> { static async inc(domainId: string, field: NumberKeys<DomainDoc>, n: number): Promise<number | null> {
domainId = domainId.toLowerCase(); domainId = domainId.toLowerCase();
const res = await coll.findOneAndUpdate( const value = await coll.findOneAndUpdate(
{ _id: domainId }, { _id: domainId },
{ $inc: { [field]: n } as any }, { $inc: { [field]: n } as any },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
bus.broadcast('domain/delete-cache', domainId); bus.broadcast('domain/delete-cache', domainId);
return res.value?.[field]; return value?.[field];
} }
@ArgMethod @ArgMethod
@@ -136,7 +136,7 @@ class DomainModel {
static async setUserRole(domainId: string, uid: MaybeArray<number>, role: string, autojoin = false) { static async setUserRole(domainId: string, uid: MaybeArray<number>, role: string, autojoin = false) {
const update = { $set: { role, ...(autojoin ? { join: true } : {}) } }; const update = { $set: { role, ...(autojoin ? { join: true } : {}) } };
if (!(uid instanceof Array)) { if (!(uid instanceof Array)) {
const res = await collUser.findOneAndUpdate({ domainId, uid }, update, { upsert: true, returnDocument: 'after' }); const res = await collUser.findOneAndUpdate({ domainId, uid }, update, { upsert: true, returnDocument: 'after', includeResultMetadata: true });
const udoc = await UserModel.getById(domainId, uid); const udoc = await UserModel.getById(domainId, uid);
deleteUserCache(udoc); deleteUserCache(udoc);
return res; return res;
+1 -2
View File
@@ -55,12 +55,11 @@ class MessageModel {
} }
static async setFlag(messageId: ObjectId, flag: number) { static async setFlag(messageId: ObjectId, flag: number) {
const result = await MessageModel.coll.findOneAndUpdate( return await MessageModel.coll.findOneAndUpdate(
{ _id: messageId }, { _id: messageId },
{ $bit: { flag: { xor: flag } } }, { $bit: { flag: { xor: flag } } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return result.value || null;
} }
static async del(_id: ObjectId) { static async del(_id: ObjectId) {
+1 -1
View File
@@ -15,7 +15,7 @@ class OauthModel {
{ $set: { uid } }, { $set: { uid } },
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
return res.value?.uid; return res?.uid;
} }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ export async function inc(op: string, ident: string, periodSecs: number, maxOper
expireAt, expireAt,
opcount: { $lt: maxOperations }, opcount: { $lt: maxOperations },
}, { $inc: { opcount: 1 } }, { upsert: true, returnDocument: 'after' }); }, { $inc: { opcount: 1 } }, { upsert: true, returnDocument: 'after' });
return res.value.opcount; return res.opcount;
} catch (e) { } catch (e) {
if (e.message.includes('duplicate')) throw new OpcountExceededError(op, periodSecs, maxOperations); if (e.message.includes('duplicate')) throw new OpcountExceededError(op, periodSecs, maxOperations);
throw e; throw e;
+1 -2
View File
@@ -209,12 +209,11 @@ export default class RecordModel {
return null; return null;
} }
if (Object.keys($update).length) { if (Object.keys($update).length) {
const res = await RecordModel.coll.findOneAndUpdate( return await RecordModel.coll.findOneAndUpdate(
{ _id, domainId }, { _id, domainId },
$update, $update,
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value || null;
} }
return await RecordModel.coll.findOne({ _id }, { readPreference: 'primary' }); return await RecordModel.coll.findOne({ _id }, { readPreference: 'primary' });
} }
+6 -6
View File
@@ -15,13 +15,13 @@ async function getFirst(query: Filter<Schedule>) {
const q = { ...query }; const q = { ...query };
q.executeAfter ||= { $lt: new Date() }; q.executeAfter ||= { $lt: new Date() };
const res = await coll.findOneAndDelete(q); const res = await coll.findOneAndDelete(q);
if (res.value) { if (res) {
logger.debug('%o', res.value); logger.debug('%o', res);
if (res.value.interval) { if (res.interval) {
const executeAfter = moment(res.value.executeAfter).add(...res.value.interval).toDate(); const executeAfter = moment(res.executeAfter).add(...res.interval).toDate();
await coll.insertOne({ ...res.value, executeAfter }); await coll.insertOne({ ...res, executeAfter });
} }
return res.value; return res;
} }
return null; return null;
} }
+7 -7
View File
@@ -35,7 +35,7 @@ export class StorageModel {
} }
static async get(path: string, savePath?: string) { static async get(path: string, savePath?: string) {
const { value } = await StorageModel.coll.findOneAndUpdate( const value = await StorageModel.coll.findOneAndUpdate(
{ path, autoDelete: null }, { path, autoDelete: null },
{ $set: { lastUsage: new Date() } }, { $set: { lastUsage: new Date() } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
@@ -101,7 +101,7 @@ export class StorageModel {
} }
static async getMeta(path: string) { static async getMeta(path: string) {
const { value } = await StorageModel.coll.findOneAndUpdate( const value = await StorageModel.coll.findOneAndUpdate(
{ path, autoDelete: null }, { path, autoDelete: null },
{ $set: { lastUsage: new Date() } }, { $set: { lastUsage: new Date() } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
@@ -120,7 +120,7 @@ export class StorageModel {
{ path: target, autoDelete: null }, { path: target, autoDelete: null },
{ $set: { lastUsage: new Date() } }, { $set: { lastUsage: new Date() } },
); );
return await storage.signDownloadLink(res.value?.link || res.value?._id || target, filename, noExpire, useAlternativeEndpointFor); return await storage.signDownloadLink(res?.link || res?._id || target, filename, noExpire, useAlternativeEndpointFor);
} }
static async move(src: string, dst: string) { static async move(src: string, dst: string) {
@@ -128,7 +128,7 @@ export class StorageModel {
{ path: src, autoDelete: null }, { path: src, autoDelete: null },
{ $set: { path: dst } }, { $set: { path: dst } },
); );
return !!res.value; return !!res;
} }
static async exists(path: string) { static async exists(path: string) {
@@ -137,7 +137,7 @@ export class StorageModel {
} }
static async copy(src: string, dst: string) { static async copy(src: string, dst: string) {
const { value } = await StorageModel.coll.findOneAndUpdate( const value = await StorageModel.coll.findOneAndUpdate(
{ path: src, autoDelete: null }, { path: src, autoDelete: null },
{ $set: { lastUsage: new Date() } }, { $set: { lastUsage: new Date() } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
@@ -170,9 +170,9 @@ async function cleanFiles() {
} }
if (system.get('server.keepFiles')) return; if (system.get('server.keepFiles')) return;
let res = await StorageModel.coll.findOneAndDelete({ autoDelete: { $lte: new Date() } }); let res = await StorageModel.coll.findOneAndDelete({ autoDelete: { $lte: new Date() } });
while (res.value) { while (res) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
if (!res.value.link) await storage.del(res.value._id); if (!res.link) await storage.del(res._id);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
res = await StorageModel.coll.findOneAndDelete({ autoDelete: { $lte: new Date() } }); res = await StorageModel.coll.findOneAndDelete({ autoDelete: { $lte: new Date() } });
} }
+4 -4
View File
@@ -45,8 +45,8 @@ export async function set(_id: string, value: any, broadcast = true) {
{ $set: { value } }, { $set: { value } },
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
cache[_id] = res.value.value; cache[_id] = res.value;
return res.value.value; return res.value;
} }
export async function inc<K extends NumberKeys<SystemKeys>>(_id: K) { export async function inc<K extends NumberKeys<SystemKeys>>(_id: K) {
@@ -55,8 +55,8 @@ export async function inc<K extends NumberKeys<SystemKeys>>(_id: K) {
{ $inc: { value: 1 } as any }, { $inc: { value: 1 } as any },
{ upsert: true, returnDocument: 'after' }, { upsert: true, returnDocument: 'after' },
); );
cache[_id] = res.value.value; cache[_id] = res.value;
return res.value.value; return res.value;
} }
export async function runConfig() { export async function runConfig() {
+5 -5
View File
@@ -19,9 +19,9 @@ async function getFirst(query: Filter<Task>) {
try { try {
const q = { ...query }; const q = { ...query };
const res = await coll.findOneAndDelete(q, { sort: { priority: -1 } }); const res = await coll.findOneAndDelete(q, { sort: { priority: -1 } });
if (res.value) { if (res) {
logger.debug('%o', res.value); logger.debug('%o', res);
return res.value; return res;
} }
return null; return null;
} catch (e) { } catch (e) {
@@ -182,9 +182,9 @@ export async function apply(ctx: Context) {
logger.error(e); logger.error(e);
continue; continue;
} }
if (argv.options.showEvent) logger.info('Event: %o', res.value); if (argv.options.showEvent) logger.info('Event: %o', res);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await (res.value ? handleEvent(res.value) : sleep(500)); await (res ? handleEvent(res) : sleep(500));
} }
}); });
await db.ensureIndexes(collEvent, { name: 'expire', key: { expire: 1 }, expireAfterSeconds: 0 }); await db.ensureIndexes(collEvent, { name: 'expire', key: { expire: 1 }, expireAfterSeconds: 0 });
+1 -1
View File
@@ -67,7 +67,7 @@ class TokenModel {
}, },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
return res.value; return res;
} }
@ArgMethod @ArgMethod
+5 -5
View File
@@ -268,7 +268,7 @@ class UserModel {
deleteUserCache(udoc); deleteUserCache(udoc);
} }
const res = await coll.findOneAndUpdate({ _id: uid }, op, { returnDocument: 'after' }); const res = await coll.findOneAndUpdate({ _id: uid }, op, { returnDocument: 'after' });
deleteUserCache(res.value); deleteUserCache(res);
return res; return res;
} }
@@ -290,8 +290,8 @@ class UserModel {
{ $set: { salt, hash: await pwhash(password, salt), hashType: 'hydro' } }, { $set: { salt, hash: await pwhash(password, salt), hashType: 'hydro' } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
deleteUserCache(res.value); deleteUserCache(res);
return res.value; return res;
} }
@ArgMethod @ArgMethod
@@ -427,8 +427,8 @@ class UserModel {
{ $set: { priv } }, { $set: { priv } },
{ returnDocument: 'after' }, { returnDocument: 'after' },
); );
deleteUserCache(res.value); deleteUserCache(res);
return res.value; return res;
} }
@ArgMethod @ArgMethod
+6 -6
View File
@@ -29,13 +29,13 @@ export class WorkerService extends Service {
subType: { $in: Object.keys(this.handlers) }, subType: { $in: Object.keys(this.handlers) },
}; };
const res = await this.coll.findOneAndDelete(q); const res = await this.coll.findOneAndDelete(q);
if (res.value) { if (res) {
this.ctx.logger.debug('%o', res.value); this.ctx.logger.debug('%o', res);
if (res.value.interval) { if (res.interval) {
const executeAfter = moment(res.value.executeAfter).add(...res.value.interval).toDate(); const executeAfter = moment(res.executeAfter).add(...res.interval).toDate();
await this.coll.insertOne({ ...res.value, executeAfter }); await this.coll.insertOne({ ...res, executeAfter });
} }
return res.value; return res;
} }
return null; return null;
} }
+1 -1
View File
@@ -7,7 +7,7 @@
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"mariadb": "^3.4.0", "mariadb": "^3.4.0",
"mongodb": "^5.9.2", "mongodb": "^6.15.0",
"turndown": "^7.2.0", "turndown": "^7.2.0",
"xml2js": "^0.6.2" "xml2js": "^0.6.2"
}, },
+1 -1
View File
@@ -13,7 +13,7 @@
"fs-extra": "^11.3.0", "fs-extra": "^11.3.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"moment-timezone": "^0.5.47", "moment-timezone": "^0.5.47",
"mongodb": "^5.9.2", "mongodb": "^6.15.0",
"reggol": "^2.1.0", "reggol": "^2.1.0",
"search-query-parser": "^1.6.0", "search-query-parser": "^1.6.0",
"systeminformation": "^5.25.11" "systeminformation": "^5.25.11"