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
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
| 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 :)
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