Skip to content

perf: group standings entries by round once instead of filtering per round#7651

Open
Rathoz wants to merge 2 commits into
standings-tests-aifrom
standings-group-entries-once
Open

perf: group standings entries by round once instead of filtering per round#7651
Rathoz wants to merge 2 commits into
standings-tests-aifrom
standings-group-entries-once

Conversation

@Rathoz

@Rathoz Rathoz commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • StandingsParser.parse previously filtered the full entry list per round three separate times (tiebreakers, placements, final-round definite statuses); replaced with a single entriesByRound grouping pass before those loops.
  • Standings.makeRounds previously ran Array.filter over all entries once per round at display time; replaced with one grouping pass keyed by tonumber(entry.roundindex) (the tonumber is preserved since records read from LPDB/wiki vars can have string roundindex).
  • Entry order within each round is preserved by sequential insertion, so placement resolution is unchanged.

Based on standings-tests-ai (PR #7647).

How did you test this change?

  • busted --run=ci: 605 successes / 0 failures / 0 errors — spec/standings_parser_spec.lua and spec/standings_model_spec.lua lock placements, ordering, and round structure.
  • luacheck on both changed files: 0 warnings / 0 errors.

🤖 Generated with Claude Code

@Rathoz Rathoz requested review from a team as code owners June 12, 2026 14:12

@ElectricalBoy ElectricalBoy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lpdb.executeMassQuery(
'standingsentry',
{
conditions = conditions:toString(),
order = 'roundindex asc',
},
function(record)
table.insert(standingsEntries, record)
end
)

adjusting LPDB query condition to have the returned data to already be sorted would be more optimal, right? like adjusting order to roundindex asc, slotindex asc
then because all data is guaranteed to be sorted we could switch over to Array.groupAdjacentBy

Comment thread lua/wikis/commons/Standings.lua Outdated
Comment on lines +234 to +241
local entriesByRound = {}
Array.forEach(standingsEntries, function(entry)
local roundIndex = tonumber(entry.roundindex)
if roundIndex then
entriesByRound[roundIndex] = entriesByRound[roundIndex] or {}
table.insert(entriesByRound[roundIndex], entry)
end
end)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Array.groupBy

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in dede56f — switched both manual grouping loops (here and the matching one in Parser.lua) to Array.groupBy.

…round

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Rathoz Rathoz force-pushed the standings-group-entries-once branch from d9dd250 to e31259a Compare June 12, 2026 16:09
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Rathoz

Rathoz commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

Applied the query-order change (roundindex asc, slotindex asc) and switched to Array.groupBy in dede56f.

groupAdjacentBy unfortunately can't be used here: makeRounds consumes standings.entryRecords, which comes from the LPDB query or from the page-variable path (getStandingsTable reading standings2_N). The var-path entries are in parser output order, which is opponent-major (flatMap(opponents, map(rounds))) — not sorted by round — so adjacency grouping would split each round into one group per opponent run. Same reason the per-round sortBy(position) stays. The grouping has to remain order-independent, which keyed Array.groupBy gives us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants