Skip to content

change the approach to obtaining user statistics data #2183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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?

@@ -332,6 +332,10 @@ defmodule Codebattle.Game.Engine do
})

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.
2 participants