perf: index standings import opponents by name instead of linear search#7653
perf: index standings import opponents by name instead of linear search#7653Rathoz wants to merge 1 commit into
Conversation
| local key = Opponent.toName(opponent) | ||
| local standingsOpponentData = opponentsByName[key] | ||
| if not standingsOpponentData and opponent.type == Opponent.team then | ||
| -- renamed teams have differing names but compare equal via historicaltemplate |
There was a problem hiding this comment.
"renamed teams have differing names" is an incorrect assumption if i am not mistaken:
- Opponent.toName returns TeamTemplate.toPageName (with normalized underscores)
- TeamTemplate.toPageName returns set pagename, resolves redirects, and normalizes underscores
A correctly setup HTT should have page redirects for each of the subtemplates to the same page.
Thus they'd end up with the same name via Opponent.toName.
This would only be different if we remove the forced resolving of redirects (which i'd personally advocate for due to A/B teams, but not sure if that is going to happen and the side effects of it)
There was a problem hiding this comment.
that is not necessarily true
there exist some team templates that have different page names set in their sub templates where no redirect exists between them
so if you would catch such a tt and process it at different dates (one before, one after the switch) you would get different pagenames returned
There was a problem hiding this comment.
What is the usecase of such a TT?
There was a problem hiding this comment.
no idea i hate them
iirc cs had some of them for some reasons
There was a problem hiding this comment.
Ah, you refer to the mibr vs MIBR things.
IIRC they fixed these by now, as they had other things broken.
There was a problem hiding this comment.
yeah exactly
if those are solved, then you are right :)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
13be265 to
1b7c81c
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes standings import from LPDB match records by replacing per-opponent linear scans with an Opponent.toName-keyed lookup table, aiming to reduce import time from O(matches × opponents) to O(matches) while preserving existing dedupe behavior (including renamed teams via historicaltemplate fallback).
Changes:
- Added an
opponentsByNamemap to indexStandingTableOpponentDatabyOpponent.toName. - Updated
parseMatchto use O(1) lookups, with a one-timeOpponent.samefallback scan for team renames. - Updated the
parseMatchcall site to pass the new map through the import flow.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local key = Opponent.toName(opponent) | ||
| local standingsOpponentData = opponentsByName[key] | ||
| if not standingsOpponentData and opponent.type == Opponent.team then | ||
| -- renamed teams have differing names but compare equal via historicaltemplate |
ElectricalBoy
left a comment
There was a problem hiding this comment.
wouldn't using return vals from Opponent.toName essentially reintroduce #6727?
iirc it was the reason we moved away from using Opponent.toName
Summary
Opponent.samescan replaced by anOpponent.toName-keyed map, reducing complexity from O(matches × opponents) to O(matches).Opponent.samefallback scan to handle renamed teams (which differ by name but compare equal viahistoricaltemplate); on a hit the new key is aliased into the map so the cost is paid at most once per renamed team.Opponent.toNamekey and are filtered out byOpponent.isTbdat the end).How did you test this change?
busted --run=ci: 605 successes / 0 failures / 0 errors — includesspec/standings_import_spec.lua(7 cases covering dedupe across rounds, TBD dropping, score mappers).luacheck lua/wikis/commons/Standings/Parse/Lpdb.lua: 0 warnings / 0 errors.🤖 Generated with Claude Code