3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 22:21:51 +00:00

Attempt to fix occasional deadlock in counter decays

This commit is contained in:
Dragory 2021-04-13 23:35:19 +03:00
parent 825bcf973f
commit c03e7240b4
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -186,14 +186,16 @@ export class GuildCounters extends BaseGuildRepository {
? `GREATEST(value - ${decayAmountToApply}, 0)` ? `GREATEST(value - ${decayAmountToApply}, 0)`
: `LEAST(value + ${Math.abs(decayAmountToApply)}, ${MAX_COUNTER_VALUE})`; : `LEAST(value + ${Math.abs(decayAmountToApply)}, ${MAX_COUNTER_VALUE})`;
await this.counterValues.update( // Using an UPDATE with ORDER BY in an attempt to avoid deadlocks from simultaneous decays
{ // Also see https://dev.mysql.com/doc/refman/8.0/en/innodb-deadlocks-handling.html
counter_id: id, await this.counterValues
}, .createQueryBuilder("CounterValue")
{ .where("counter_id = :id", { id })
.orderBy("id")
.update({
value: () => rawUpdate, value: () => rawUpdate,
}, })
); .execute();
await this.counters.update( await this.counters.update(
{ {