mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: del user cache on group update (#552)
This commit is contained in:
1 parent
5a06be3208
commit
342e9585dd
2 files changed
+13
-11
No files matched your search
@@ -7,13 +7,13 @@ import { PRIV } from './builtin';
|
||||
import * as system from './system';
|
||||
import user from './user';
|
||||
|
||||
const coll = db.collection('message');
|
||||
|
||||
class MessageModel {
|
||||
static FLAG_UNREAD = 1;
|
||||
static FLAG_ALERT = 2;
|
||||
static FLAG_RICHTEXT = 4;
|
||||
|
||||
static coll = db.collection('message');
|
||||
|
||||
@ArgMethod
|
||||
static async send(
|
||||
from: number, to: number,
|
||||
@@ -23,29 +23,29 @@ class MessageModel {
|
||||
const mdoc: MessageDoc = {
|
||||
_id, from, to, content, flag,
|
||||
};
|
||||
await coll.insertOne(mdoc);
|
||||
await MessageModel.coll.insertOne(mdoc);
|
||||
if (from !== to) bus.broadcast('user/message', to, mdoc);
|
||||
if (flag & MessageModel.FLAG_UNREAD) await user.inc(to, 'unreadMsg', 1);
|
||||
return mdoc;
|
||||
}
|
||||
|
||||
static async get(_id: ObjectId) {
|
||||
return await coll.findOne({ _id });
|
||||
return await MessageModel.coll.findOne({ _id });
|
||||
}
|
||||
|
||||
@ArgMethod
|
||||
static async getByUser(uid: number) {
|
||||
return await coll.find({ $or: [{ from: uid }, { to: uid }] }).sort('_id', -1).limit(1000).toArray();
|
||||
return await MessageModel.coll.find({ $or: [{ from: uid }, { to: uid }] }).sort('_id', -1).limit(1000).toArray();
|
||||
}
|
||||
|
||||
static async getMany(query: Filter<MessageDoc>, sort: any, page: number, limit: number) {
|
||||
return await coll.find(query).sort(sort)
|
||||
return await MessageModel.coll.find(query).sort(sort)
|
||||
.skip((page - 1) * limit).limit(limit)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
static async setFlag(messageId: ObjectId, flag: number) {
|
||||
const result = await coll.findOneAndUpdate(
|
||||
const result = await MessageModel.coll.findOneAndUpdate(
|
||||
{ _id: messageId },
|
||||
{ $bit: { flag: { xor: flag } } },
|
||||
{ returnDocument: 'after' },
|
||||
@@ -54,16 +54,16 @@ class MessageModel {
|
||||
}
|
||||
|
||||
static async del(_id: ObjectId) {
|
||||
return await coll.deleteOne({ _id });
|
||||
return await MessageModel.coll.deleteOne({ _id });
|
||||
}
|
||||
|
||||
@ArgMethod
|
||||
static count(query: Filter<MessageDoc> = {}) {
|
||||
return coll.countDocuments(query);
|
||||
return MessageModel.coll.countDocuments(query);
|
||||
}
|
||||
|
||||
static getMulti(uid: number) {
|
||||
return coll.find({ $or: [{ from: uid }, { to: uid }] });
|
||||
return MessageModel.coll.find({ $or: [{ from: uid }, { to: uid }] });
|
||||
}
|
||||
|
||||
static async sendNotification(message: string, ...args: any[]) {
|
||||
@@ -78,7 +78,7 @@ class MessageModel {
|
||||
|
||||
export async function apply() {
|
||||
return db.ensureIndexes(
|
||||
coll,
|
||||
MessageModel.coll,
|
||||
{ key: { to: 1, _id: -1 }, name: 'to' },
|
||||
{ key: { from: 1, _id: -1 }, name: 'from' },
|
||||
);
|
||||
|
||||
@@ -441,10 +441,12 @@ class UserModel {
|
||||
}
|
||||
|
||||
static delGroup(domainId: string, name: string) {
|
||||
deleteUserCache(domainId);
|
||||
return collGroup.deleteOne({ domainId, name });
|
||||
}
|
||||
|
||||
static updateGroup(domainId: string, name: string, uids: number[]) {
|
||||
deleteUserCache(domainId);
|
||||
return collGroup.updateOne({ domainId, name }, { $set: { uids } }, { upsert: true });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user