mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: usercache: broadcast check
This commit is contained in:
1 parent
bbca622353
commit
5602fab01c
2 files changed
+4
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.32.7",
|
"version": "2.32.8",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ const coll: Collection<Udoc> = db.collection('user');
|
|||||||
const logger = new Logger('model/user');
|
const logger = new Logger('model/user');
|
||||||
const cache = new LRU<string, User>({ max: 500, maxAge: 300 * 1000 });
|
const cache = new LRU<string, User>({ max: 500, maxAge: 300 * 1000 });
|
||||||
|
|
||||||
export function deleteUserCache(udoc: User | Udoc | string | undefined | null) {
|
export function deleteUserCache(udoc: User | Udoc | string | undefined | null, receiver = false) {
|
||||||
if (!udoc) return;
|
if (!udoc) return;
|
||||||
bus.broadcast('user/delcache', JSON.stringify(udoc));
|
if (!receiver) bus.broadcast('user/delcache', JSON.stringify(udoc));
|
||||||
if (typeof udoc === 'string') {
|
if (typeof udoc === 'string') {
|
||||||
for (const key of cache.keys().filter((k) => k.endsWith(`/${udoc}`))) {
|
for (const key of cache.keys().filter((k) => k.endsWith(`/${udoc}`))) {
|
||||||
cache.del(key);
|
cache.del(key);
|
||||||
@@ -35,7 +35,7 @@ export function deleteUserCache(udoc: User | Udoc | string | undefined | null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bus.on('user/delcache', (content) => deleteUserCache(JSON.parse(content)));
|
bus.on('user/delcache', (content) => deleteUserCache(JSON.parse(content), true));
|
||||||
|
|
||||||
class User implements _User {
|
class User implements _User {
|
||||||
_id: number;
|
_id: number;
|
||||||
|
|||||||
Reference in new issue
Block a user