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:
parent
825bcf973f
commit
c03e7240b4
1 changed files with 9 additions and 7 deletions
|
@ -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(
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue