3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

Fix race conditions and duplicate stars in starboard

This commit is contained in:
Dragory 2020-12-23 05:28:21 +02:00
parent 1484f6b9a7
commit e1e1854041
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
5 changed files with 63 additions and 9 deletions

View file

@ -36,6 +36,8 @@ export const StarboardReactionAddEvt = starboardEvt({
categoryId: (msg.channel as TextChannel).parentID,
});
const boardLock = await pluginData.locks.acquire(`starboards`);
const applicableStarboards = Object.values(config.boards)
.filter(board => board.enabled)
// Can't star messages in the starboard channel itself
@ -59,8 +61,6 @@ export const StarboardReactionAddEvt = starboardEvt({
});
for (const starboard of applicableStarboards) {
const boardLock = await pluginData.locks.acquire(`starboards-channel-${starboard.channel_id}`);
// Save reaction into the database
await pluginData.state.starboardReactions.createStarboardReaction(msg.id, userId).catch(noop);
@ -92,8 +92,8 @@ export const StarboardReactionAddEvt = starboardEvt({
// Otherwise, if the star count exceeds the required star count, save the message to the starboard
await saveMessageToStarboard(pluginData, msg, starboard);
}
boardLock.unlock();
}
boardLock.unlock();
},
});