feat(Server): invalidate caches on changes

This commit is contained in:
41666 2020-02-04 08:10:04 -05:00
parent 0e70e2590b
commit 4ffd5014df
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
3 changed files with 32 additions and 2 deletions

View file

@ -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)