Skip to content

Make a bulk update instead of queries in loop #125

@ahmadbky

Description

@ahmadbky

for (player, score) in scores.player_scores {
players::Entity::update(players::ActiveModel {
id: Set(player.inner.id),
score: Set(score),
..Default::default()
})
.exec(txn)
.await?;
pipe.zadd(player_ranking(), player.inner.id, score);
}
for (map, score) in scores.map_scores {
maps::Entity::update(maps::ActiveModel {
id: Set(map.inner.id),
score: Set(score),
..Default::default()
})
.exec(txn)
.await?;
pipe.zadd(map_ranking(), map.inner.id, score);
}

This is bad and should be changed into a bulk update. The update could be made through the UPDATE FROM (VALUES ...) syntax, available in Postgres, or with a CASE WHEN for each entry for MariaDB/MySQL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions