mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-24 19:59:12 +00:00
feat(Server): invalidate caches on changes
This commit is contained in:
parent
0e70e2590b
commit
4ffd5014df
3 changed files with 32 additions and 2 deletions
|
@ -89,7 +89,11 @@ module.exports = (R, $) => {
|
|||
...(categories != null ? { categories } : {}),
|
||||
})
|
||||
|
||||
|
||||
ctx.body = { ok: true }
|
||||
|
||||
$.P.invalidate(id)
|
||||
$.discord.invalidate(id)
|
||||
})
|
||||
|
||||
R.get('/api/admin/servers', async ctx => {
|
||||
|
@ -131,8 +135,16 @@ module.exports = (R, $) => {
|
|||
// last, add new roles
|
||||
newRoles = [...newRoles, ...sanitizedAdded]
|
||||
|
||||
await $.discord.updateRoles(gm, newRoles)
|
||||
if (!arrayMatches(currentRoles, newRoles)) {
|
||||
await $.discord.updateRoles(gm, newRoles)
|
||||
}
|
||||
|
||||
ctx.body = { ok: true }
|
||||
|
||||
$.P.invalidate(userId)
|
||||
$.discord.invalidate(userId)
|
||||
})
|
||||
}
|
||||
|
||||
const arrayMatches = (a, b) =>
|
||||
a.length === b.length && a.reduce((_, aValue) => b.contains(aValue), true)
|
|
@ -238,6 +238,15 @@ class DiscordService extends Service {
|
|||
|
||||
return returnVal
|
||||
}
|
||||
|
||||
invalidate(deadKey) {
|
||||
const keys = this.cache.keys()
|
||||
for (let key of keys) {
|
||||
if (key.includes(deadKey)) {
|
||||
this.cache.del(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DiscordService
|
||||
|
|
|
@ -58,7 +58,7 @@ class PresentationService extends Service {
|
|||
roles: serverRoles,
|
||||
message: serverData.message,
|
||||
categories: serverData.categories,
|
||||
perms: this.discord.getPermissions(member, serverRoles, server),
|
||||
perms: this.discord.getPermissions(member, serverRoles),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -74,6 +74,15 @@ class PresentationService extends Service {
|
|||
|
||||
return returnVal
|
||||
}
|
||||
|
||||
invalidate(deadKey) {
|
||||
const keys = this.cache.keys()
|
||||
for (let key of keys) {
|
||||
if (key.includes(deadKey)) {
|
||||
this.cache.del(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PresentationService
|
||||
|
|
Loading…
Add table
Reference in a new issue