From e31259ab22adbc6c1df44aedef95d7d8fcac352b Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Fri, 12 Jun 2026 16:11:57 +0200 Subject: [PATCH 1/2] perf: group standings entries by round once instead of filtering per round Co-Authored-By: Claude Fable 5 --- lua/wikis/commons/Standings.lua | 15 +++++++++++---- lua/wikis/commons/Standings/Parser.lua | 18 +++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lua/wikis/commons/Standings.lua b/lua/wikis/commons/Standings.lua index da891d1d3cb..3cebd7725ad 100644 --- a/lua/wikis/commons/Standings.lua +++ b/lua/wikis/commons/Standings.lua @@ -231,11 +231,18 @@ function Standings.makeRounds(standings) local roundCount = Array.maxBy(Array.map(standingsEntries, function(entry) return tonumber(entry.roundindex) or 1 end), FnUtil.identity) + 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) + return Array.mapRange(1, roundCount or 1, function(roundIndex) - local roundEntries = Array.filter(standingsEntries, function(entry) - return tonumber(entry.roundindex) == roundIndex - end) - local opponents = Array.sortBy(Array.map(roundEntries, Standings.entryFromRecord), Operator.property('position')) + local roundEntries = Array.map(entriesByRound[roundIndex] or {}, Standings.entryFromRecord) + local opponents = Array.sortBy(roundEntries, Operator.property('position')) return { round = roundIndex, opponents = opponents, diff --git a/lua/wikis/commons/Standings/Parser.lua b/lua/wikis/commons/Standings/Parser.lua index da58111abc0..12644fb64f4 100644 --- a/lua/wikis/commons/Standings/Parser.lua +++ b/lua/wikis/commons/Standings/Parser.lua @@ -76,16 +76,18 @@ function StandingsParser.parse(rounds, opponents, bgs, title, matches, standings end) end) + local entriesByRound = {} + Array.forEach(entries, function(entry) + entriesByRound[entry.roundindex] = entriesByRound[entry.roundindex] or {} + table.insert(entriesByRound[entry.roundindex], entry) + end) + Array.forEach(rounds, function(round) - StandingsParser.calculateTiebreakerValues(Array.filter(entries, function(opponentRound) - return opponentRound.roundindex == round.roundNumber - end), tiebreakerIds) + StandingsParser.calculateTiebreakerValues(entriesByRound[round.roundNumber] or {}, tiebreakerIds) end) Array.forEach(rounds, function(round) - StandingsParser.determinePlacements(Array.filter(entries, function(opponentRound) - return opponentRound.roundindex == round.roundNumber - end), tiebreakerIds) + StandingsParser.determinePlacements(entriesByRound[round.roundNumber] or {}, tiebreakerIds) end) ---@cast entries {opponent: standardOpponent, standingindex: integer, roundindex: integer, ---points: number, placement: integer?, slotindex: integer}[] @@ -96,9 +98,7 @@ function StandingsParser.parse(rounds, opponents, bgs, title, matches, standings StandingsParser.addStatuses(entries, bgs, 'currentstatus') if isFinished then - StandingsParser.addStatuses(Array.filter(entries, function(opponentRound) - return opponentRound.roundindex == #rounds - end), bgs, 'definitestatus') + StandingsParser.addStatuses(entriesByRound[#rounds] or {}, bgs, 'definitestatus') end ---@cast entries {opponent: standardOpponent, standingindex: integer, roundindex: integer, points: number, ---placement: integer?, slotindex: integer, placementchange: integer?, From dede56fb0d2bb763b205befefdd31549414d3dc9 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Fri, 12 Jun 2026 18:18:17 +0200 Subject: [PATCH 2/2] refactor: use Array.groupBy for round grouping and order entries query Co-Authored-By: Claude Fable 5 --- lua/wikis/commons/Standings.lua | 11 +++-------- lua/wikis/commons/Standings/Parser.lua | 6 ++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lua/wikis/commons/Standings.lua b/lua/wikis/commons/Standings.lua index 3cebd7725ad..3d86bc63352 100644 --- a/lua/wikis/commons/Standings.lua +++ b/lua/wikis/commons/Standings.lua @@ -213,7 +213,7 @@ function Standings.fetchEntries(standings) 'standingsentry', { conditions = conditions:toString(), - order = 'roundindex asc', + order = 'roundindex asc, slotindex asc', }, function(record) table.insert(standingsEntries, record) @@ -231,13 +231,8 @@ function Standings.makeRounds(standings) local roundCount = Array.maxBy(Array.map(standingsEntries, function(entry) return tonumber(entry.roundindex) or 1 end), FnUtil.identity) - 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 + local _, entriesByRound = Array.groupBy(standingsEntries, function(entry) + return tonumber(entry.roundindex) end) return Array.mapRange(1, roundCount or 1, function(roundIndex) diff --git a/lua/wikis/commons/Standings/Parser.lua b/lua/wikis/commons/Standings/Parser.lua index 12644fb64f4..59a505fddd6 100644 --- a/lua/wikis/commons/Standings/Parser.lua +++ b/lua/wikis/commons/Standings/Parser.lua @@ -76,10 +76,8 @@ function StandingsParser.parse(rounds, opponents, bgs, title, matches, standings end) end) - local entriesByRound = {} - Array.forEach(entries, function(entry) - entriesByRound[entry.roundindex] = entriesByRound[entry.roundindex] or {} - table.insert(entriesByRound[entry.roundindex], entry) + local _, entriesByRound = Array.groupBy(entries, function(entry) + return entry.roundindex end) Array.forEach(rounds, function(round)