Skip to content

Commit 0d5defe

Browse files
committed
fix: solve team mismatch
1 parent d76ba49 commit 0d5defe

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

app/modules/analytics/controllers/performance_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class PerformanceController < Api::V1::BaseController
4444
# @param player_id [Integer] Player ID for individual stats (optional)
4545
# @return [JSON] Performance analytics data
4646
def index
47-
# Use active players for team-wide stats (best performers, role breakdown, etc.)
48-
# but validate player_id against ALL org players so that bench/trial/inactive
49-
# players can still have their individual stats viewed.
47+
# Use all non-deleted org players for team-wide stats (best performers, role
48+
# breakdown, etc.) so that bench/trial/inactive players who have match stats
49+
# still appear in the leaderboard. Individual player stats use the same scope.
5050
all_org_players = organization_scoped(Player).includes(:organization)
5151
player_id = params[:player_id].presence
5252

@@ -61,8 +61,7 @@ def index
6161
cache_key = performance_cache_key(player_id)
6262
data = cache_response(cache_key, expires_in: 15.minutes) do
6363
matches = apply_date_filters(organization_scoped(Match))
64-
active_players = organization_scoped(Player).includes(:organization).active
65-
service = PerformanceAnalyticsService.new(matches, active_players)
64+
service = PerformanceAnalyticsService.new(matches, all_org_players)
6665
service.calculate_performance_data(player_id: player_id, all_players: all_org_players)
6766
end
6867

app/modules/analytics/services/performance_analytics_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def initialize(matches, players)
2828
#
2929
# @param player_id [Integer, nil] Optional player ID for individual stats
3030
# @param all_players [ActiveRecord::Relation, nil] Scope to resolve the individual player
31-
# from. Defaults to @players (active only). Pass the full org scope when you want to
32-
# allow individual stats for inactive/bench/trial players too.
31+
# from. Defaults to @players. Pass a different scope when you want to restrict or
32+
# expand the set of players eligible for individual stat lookup.
3333
# @return [Hash] Performance analytics data
3434
def calculate_performance_data(player_id: nil, all_players: nil)
3535
if player_id

0 commit comments

Comments
 (0)