mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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 * as system from './system';
|
||||||
import user from './user';
|
import user from './user';
|
||||||
|
|
||||||
const coll = db.collection('message');
|
|
||||||
|
|
||||||
class MessageModel {
|
class MessageModel {
|
||||||
static FLAG_UNREAD = 1;
|
static FLAG_UNREAD = 1;
|
||||||
static FLAG_ALERT = 2;
|
static FLAG_ALERT = 2;
|
||||||
static FLAG_RICHTEXT = 4;
|
static FLAG_RICHTEXT = 4;
|
||||||
|
|
||||||
|
static coll = db.collection('message');
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async send(
|
static async send(
|
||||||
from: number, to: number,
|
from: number, to: number,
|
||||||
@@ -23,29 +23,29 @@ class MessageModel {
|
|||||||
const mdoc: MessageDoc = {
|
const mdoc: MessageDoc = {
|
||||||
_id, from, to, content, flag,
|
_id, from, to, content, flag,
|
||||||
};
|
};
|
||||||
await coll.insertOne(mdoc);
|
await MessageModel.coll.insertOne(mdoc);
|
||||||
if (from !== to) bus.broadcast('user/message', to, mdoc);
|
if (from !== to) bus.broadcast('user/message', to, mdoc);
|
||||||
if (flag & MessageModel.FLAG_UNREAD) await user.inc(to, 'unreadMsg', 1);
|
if (flag & MessageModel.FLAG_UNREAD) await user.inc(to, 'unreadMsg', 1);
|
||||||
return mdoc;
|
return mdoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async get(_id: ObjectId) {
|
static async get(_id: ObjectId) {
|
||||||
return await coll.findOne({ _id });
|
return await MessageModel.coll.findOne({ _id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async getByUser(uid: number) {
|
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) {
|
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)
|
.skip((page - 1) * limit).limit(limit)
|
||||||
.toArray();
|
.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setFlag(messageId: ObjectId, flag: number) {
|
static async setFlag(messageId: ObjectId, flag: number) {
|
||||||
const result = await coll.findOneAndUpdate(
|
const result = await MessageModel.coll.findOneAndUpdate(
|
||||||
{ _id: messageId },
|
{ _id: messageId },
|
||||||
{ $bit: { flag: { xor: flag } } },
|
{ $bit: { flag: { xor: flag } } },
|
||||||
{ returnDocument: 'after' },
|
{ returnDocument: 'after' },
|
||||||
@@ -54,16 +54,16 @@ class MessageModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async del(_id: ObjectId) {
|
static async del(_id: ObjectId) {
|
||||||
return await coll.deleteOne({ _id });
|
return await MessageModel.coll.deleteOne({ _id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static count(query: Filter<MessageDoc> = {}) {
|
static count(query: Filter<MessageDoc> = {}) {
|
||||||
return coll.countDocuments(query);
|
return MessageModel.coll.countDocuments(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getMulti(uid: number) {
|
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[]) {
|
static async sendNotification(message: string, ...args: any[]) {
|
||||||
@@ -78,7 +78,7 @@ class MessageModel {
|
|||||||
|
|
||||||
export async function apply() {
|
export async function apply() {
|
||||||
return db.ensureIndexes(
|
return db.ensureIndexes(
|
||||||
coll,
|
MessageModel.coll,
|
||||||
{ key: { to: 1, _id: -1 }, name: 'to' },
|
{ key: { to: 1, _id: -1 }, name: 'to' },
|
||||||
{ key: { from: 1, _id: -1 }, name: 'from' },
|
{ key: { from: 1, _id: -1 }, name: 'from' },
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -441,10 +441,12 @@ class UserModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static delGroup(domainId: string, name: string) {
|
static delGroup(domainId: string, name: string) {
|
||||||
|
deleteUserCache(domainId);
|
||||||
return collGroup.deleteOne({ domainId, name });
|
return collGroup.deleteOne({ domainId, name });
|
||||||
}
|
}
|
||||||
|
|
||||||
static updateGroup(domainId: string, name: string, uids: number[]) {
|
static updateGroup(domainId: string, name: string, uids: number[]) {
|
||||||
|
deleteUserCache(domainId);
|
||||||
return collGroup.updateOne({ domainId, name }, { $set: { uids } }, { upsert: true });
|
return collGroup.updateOne({ domainId, name }, { $set: { uids } }, { upsert: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user