Skip to content

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

Open
Rathoz wants to merge 3 commits into
mainfrom
standings-group-entries-once
Open

perf: group standings entries by round once instead of filtering per round#7651
Rathoz wants to merge 3 commits into
mainfrom
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.

@Rathoz Rathoz force-pushed the standings-group-entries-once branch from d9dd250 to e31259a Compare June 12, 2026 16:09
@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.

Base automatically changed from standings-tests-ai to main July 2, 2026 09:51
Rathoz and others added 2 commits July 2, 2026 11:54
…round

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 2, 2026 09:54
@Rathoz Rathoz force-pushed the standings-group-entries-once branch from dede56f to 808b763 Compare July 2, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors standings parsing and model round-building to avoid repeatedly filtering the full entries list per round, replacing those repeated Array.filter passes with a single Array.groupBy pre-grouping keyed by round index to reduce overall work.

Changes:

  • In StandingsParser.parse, pre-groups computed entries by roundindex once and reuses the grouped lists for tiebreaker calculation, placement resolution, and final-round definitive status assignment.
  • In Standings.makeRounds, pre-groups LPDB standingsentry records by tonumber(roundindex) once and maps/sorts per-round entries from that grouped structure (instead of filtering per round).
  • Adjusts LPDB query ordering to roundindex asc, slotindex asc for more deterministic record ordering during fetch.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lua/wikis/commons/Standings/Parser.lua Replaces per-round filtering with a single grouping pass reused across the round-based computation loops.
lua/wikis/commons/Standings.lua Replaces per-round filtering during round construction with a single grouping pass; refines LPDB ordering for fetched entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Rathoz Rathoz requested a review from ElectricalBoy July 9, 2026 13:01
Comment thread lua/wikis/commons/Standings.lua Outdated
Co-authored-by: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com>
@Rathoz Rathoz requested a review from ElectricalBoy July 9, 2026 13:09
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.

3 participants