Skip to content

Conversation

WhereIU
Copy link

@WhereIU WhereIU commented Jun 25, 2025

Closes #2182

@ReDBrother ReDBrother self-requested a review June 29, 2025 10:21
end

defp calculate_stats(user_games) do
total_games = length(user_games)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's get all these count in SQL query

stats = calculate_stats(user_games)

case Repo.get_by(UserGameStatistics, user_id: user_id) do
nil ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let' write insert on conflict (user_id) update

field :total_losses, :integer
field :total_giveups, :integer, default: 0
field :versus_bot_games, :integer
field :versus_human_games, :integer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need versus_bot_games and versus_human_games?

update_user!(player)

unless player.is_bot or player.is_guest do
Codebattle.UserGameStatistics.Context.update_user_stats(player.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it async

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Change search strategy for user statistics.
3 participants