From 57b46a8ecec4abb18f9208b67cd6bdb424d8468c Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Wed, 24 Jun 2026 16:12:03 +0200 Subject: [PATCH 1/5] refactor: cleanup match ticker step 3 --- lua/wikis/commons/MatchTicker/Controller.lua | 144 +++++++++--------- .../commons/Widget/Match/Ticker/Wrapper.lua | 13 +- 2 files changed, 73 insertions(+), 84 deletions(-) diff --git a/lua/wikis/commons/MatchTicker/Controller.lua b/lua/wikis/commons/MatchTicker/Controller.lua index 751b2f6f9f0..5ad48e77bb7 100644 --- a/lua/wikis/commons/MatchTicker/Controller.lua +++ b/lua/wikis/commons/MatchTicker/Controller.lua @@ -12,7 +12,6 @@ local FnUtil = Lua.import('Module:FnUtil') local Game = Lua.import('Module:Game') local Logic = Lua.import('Module:Logic') local Lpdb = Lua.import('Module:Lpdb') -local Operator = Lua.import('Module:Operator') local String = Lua.import('Module:StringUtils') local Table = Lua.import('Module:Table') local TeamTemplate = Lua.import('Module:TeamTemplate') @@ -32,7 +31,7 @@ local Comparator = Condition.Comparator local BooleanOperator = Condition.BooleanOperator local ColumnName = Condition.ColumnName -local DEFAULT_QUERY_COLUMNS = { +local QUERY_COLUMNS = { 'match2opponents', 'winner', 'pagename', @@ -72,7 +71,6 @@ local NOW = os.date('%Y-%m-%d %H:%M', os.time(os.date('!*t') --[[@as osdateparam ---@field player string? ---@field teamPages string[]? ---@field hideTournament boolean ----@field queryColumns string[] ---@field additionalConditions string ---@field recent boolean ---@field upcoming boolean @@ -94,7 +92,6 @@ local NOW = os.date('%Y-%m-%d %H:%M', os.time(os.date('!*t') --[[@as osdateparam ---@field header Renderable? ---@class MatchTickerGameData ----@field asGame boolean? ---@field gameIds number[] ---@field map string? ---@field mapDisplayName string? @@ -133,7 +130,6 @@ function MatchTickerController.parseConfig(args) limit = tonumber(args.limit) or DEFAULT_LIMIT, order = args.order or (Logic.readBool(args.recent) and DEFAULT_RECENT_ORDER or DEFAULT_ORDER), player = args.player and mw.ext.TeamLiquidIntegration.resolve_redirect(args.player):gsub(' ', '_') or nil, - queryColumns = args.queryColumns or DEFAULT_QUERY_COLUMNS, additionalConditions = args.additionalConditions or '', recent = Logic.readBool(args.recent), upcoming = Logic.readBool(args.upcoming), @@ -208,22 +204,27 @@ end ---queries the matches and filters them for unwanted ones ---@private ---@param config MatchTickerConfig ----@return table[] +---@return {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] function MatchTickerController.fetchMatches(config) + local shouldFetchTournamentData = config.regions or config.featuredOnly local matches = {} Lpdb.executeMassQuery('match2', { conditions = MatchTickerController.buildQueryConditions(config), order = config.order, - query = table.concat(config.queryColumns, ','), + query = table.concat(QUERY_COLUMNS, ','), limit = DEFAULT_LIMIT, }, function(record) - record = MatchTickerController.parseMatch(record, config) - if not MatchTickerController.keepMatch(record, config) then + local parsedMatch = MatchGroupUtil.matchFromRecord(record) + local tournamentData + if shouldFetchTournamentData then + tournamentData = MatchTickerController.fetchTournament(parsedMatch.parent) + end + if not MatchTickerController.keepMatch(parsedMatch, tournamentData, config) then return end - for _, match in ipairs(MatchTickerController.expandGamesOfMatch(record, config)) do + for _, match in ipairs(MatchTickerController.expandGamesOfMatch(parsedMatch, config)) do table.insert(matches, match) end if #matches >= config.limit then @@ -358,41 +359,28 @@ function MatchTickerController.dateConditions(config) return dateConditions:add{ConditionNode(ColumnName('date'), Comparator.gt, NOW)} end ----@private ----@param match table ----@param config MatchTickerConfig ----@return table -function MatchTickerController.parseMatch(match, config) - match.opponents = Array.map(match.match2opponents, function(opponent, opponentIndex) - return MatchGroupUtil.opponentFromRecord(match, opponent, opponentIndex) - end) - if config.regions or config.featuredOnly then - match.tournamentData = MatchTickerController.fetchTournament(match.parent) - end - return match -end - local previousMatchWasTbd = false ---@private ----@param match table +---@param match MatchGroupUtilMatch +---@param tournamentData StandardTournament? ---@param config MatchTickerConfig ---@return boolean -function MatchTickerController.keepMatch(match, config) +function MatchTickerController.keepMatch(match, tournamentData, config) if match.extradata and match.extradata.hidden then return false end -- Remove matches with wrong region if config.regions then - if not match.tournamentData then + if not tournamentData then return false end - if not Table.includes(config.regions, match.tournamentData.region) then + if not Table.includes(config.regions, tournamentData.region) then return false end end if config.featuredOnly then - local matchIsInFeaturedTournament = match.tournamentData and match.tournamentData.featured + local matchIsInFeaturedTournament = tournamentData and tournamentData.featured local matchIsFeatured = match.extradata and match.extradata.featured if not matchIsInFeaturedTournament and not matchIsFeatured then return false @@ -418,90 +406,102 @@ function MatchTickerController.keepMatch(match, config) end ---@private ----@param match table +---@param match MatchGroupUtilMatch ---@param config MatchTickerConfig ----@return table[] +---@return {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] function MatchTickerController.expandGamesOfMatch(match, config) - if not match.match2games or #match.match2games < 2 then - return {match} + if not match.games or #match.games < 2 then + return {{match = match}} end - if Array.all(match.match2games, function(game) return game.date == match.date end) then - return {match} + if Array.all(match.games, function(game) return game.date == match.date end) then + return {{match = match}} end - local expandedGames = Array.map(match.match2games, function(game, gameIndex) + local gamesToExpand = Array.filter(match.games, function(game) if config.recent and Logic.isEmpty(game.winner) then - return + return false end if (config.upcoming or config.ongoing) and Logic.isNotEmpty(game.winner) then - return + return false end if not game.date then - return + return false end if not config.upcoming and NOW < game.date then - return + return false end if not (config.ongoing or config.recent) and NOW >= game.date then - return + return false end + return true + end) + + local expandedGames = Array.map(gamesToExpand, function(game, gameIndex) local gameMatch = Table.copy(match) - gameMatch.match2games = {} - gameMatch.asGame = true - gameMatch.asGameIndexes = {gameIndex} + gameMatch.games = {} gameMatch.winner = game.winner gameMatch.date = game.date - gameMatch.map = game.map gameMatch.vod = Logic.nilIfEmpty(game.vod) or match.vod - gameMatch.opponents = Array.map(match.match2opponents, function(opponent, opponentIndex) + gameMatch.opponents = Array.map(match.opponents, function(opponent, opponentIndex) return MatchUtil.enrichGameOpponentFromMatchOpponent(opponent, game.opponents[opponentIndex]) end) - gameMatch.match2opponents = gameMatch.opponents gameMatch.extradata = Table.merge(gameMatch.extradata, game.extradata) - return gameMatch + ---@type MatchTickerGameData + local gameData = { + gameIds = {gameIndex}, + map = game.map, + mapDisplayName = game.extradata and game.extradata.displayname + } + return {match = gameMatch, gameData = gameData} end) - return Array.map(Array.groupAdjacentBy(expandedGames, Operator.property('date')), function (gameGroup) - if #gameGroup > 1 then - local lastIndexes = gameGroup[#gameGroup].asGameIndexes - table.insert(gameGroup[1].asGameIndexes, lastIndexes[#lastIndexes]) - end + return Array.map( + Array.groupAdjacentBy( + expandedGames, + function(gameAsMatch) return gameAsMatch.match.date end + ), + function (gameGroup) + if #gameGroup > 1 then + local lastIds = gameGroup[#gameGroup].gameData.gameIds + table.insert(gameGroup[1].gameData.gameIds, lastIds[#lastIds]) + end - return gameGroup[1] - end) + return {match = gameGroup[1].match, gameData = gameGroup[1].gameData} + end + ) end ---@private ----@param matches table[] +---@param matches {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] ---@param config MatchTickerConfig ----@return table[] +---@return {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] function MatchTickerController.sortMatches(matches, config) local reverse = config.recent and true or false return Array.sortBy(matches, FnUtil.identity, function (a, b) - if a.date ~= b.date then + local aDate, bDate = a.match.date, b.match.date + if aDate ~= bDate then if reverse then - return a.date > b.date + return aDate > bDate end - return b.date > a.date + return bDate > aDate end - if a.match2id ~= b.match2id then - return a.match2id < b.match2id + if a.match.match2id ~= b.match.match2id then + return a.match.match2id < b.match.match2id end - return ((a.asGameIndexes or {})[1] or 0) < ((b.asGameIndexes or {})[1] or 0) + return (((a.gameData or {}).gameIds or {})[1] or 0) < (((b.gameData or {}).gameIds or {})[1] or 0) end) end --- Will only switch if enteredOpponentOnLeft is enabled AND there are exactly 2 opponents ---@private ----@param match table +---@param match MatchGroupUtilMatch ---@param config MatchTickerConfig ----@return table function MatchTickerController.adjustMatch(match, config) if not config.enteredOpponentOnLeft or #match.opponents ~= 2 then - return match + return end local opponentNames = Array.extend({config.player}, config.teamPages) @@ -512,29 +512,23 @@ function MatchTickerController.adjustMatch(match, config) or config.player and Table.any(match.opponents[2].players, function(_, playerData) return (playerData.pageName or ''):gsub(' ', '_') == config.player end) then - return MatchTickerController.switchOpponents(match) + MatchTickerController.switchOpponents(match) end - - return match end --- Will only switch if there are exactly 2 opponents ---@private ----@param match table ----@return table +---@param match MatchGroupUtilMatch function MatchTickerController.switchOpponents(match) if #match.opponents ~= 2 then - return match + return end local winner = tonumber(match.winner) or 0 match.winner = winner == 1 and 2 or winner == 2 and 1 or match.winner - match.match2opponents[1], match.match2opponents[2] = match.match2opponents[2], match.match2opponents[1] match.opponents[1], match.opponents[2] = match.opponents[2], match.opponents[1] - - return match end --- Fetches region of a tournament diff --git a/lua/wikis/commons/Widget/Match/Ticker/Wrapper.lua b/lua/wikis/commons/Widget/Match/Ticker/Wrapper.lua index dcfe0c37e39..db7a0146dac 100644 --- a/lua/wikis/commons/Widget/Match/Ticker/Wrapper.lua +++ b/lua/wikis/commons/Widget/Match/Ticker/Wrapper.lua @@ -9,13 +9,13 @@ local Lua = require('Module:Lua') local Array = Lua.import('Module:Array') local Component = Lua.import('Module:Widget/Component') -local MatchGroupUtil = Lua.import('Module:MatchGroup/Util/Custom') local Html = Lua.import('Module:Widget/Html') local MatchCard = Lua.import('Module:Widget/Match/Card') local HorizontalContainer = Lua.import('Module:Widget/Match/Ticker/HorizontalContainer') ----@param props {matches: table[], header: Renderable?, showInfoForEmptyResults: boolean, wrapperClasses: string[], +---@param props {matches: {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[], +---header: Renderable?, showInfoForEmptyResults: boolean, wrapperClasses: string[], ---hideTournament: boolean, displayGameIcons: boolean, onlyHighlightOnValue: string?, variant: 'vertical'|'horizontal'} ---@return Renderable? local function MatchTickerWrapper(props) @@ -36,17 +36,12 @@ local function MatchTickerWrapper(props) local matchCards = Array.map(matches, function(match) return MatchCard{ - match = MatchGroupUtil.matchFromRecord(match), + match = match.match, hideTournament = props.hideTournament, displayGameIcons = props.displayGameIcons, onlyHighlightOnValue = props.onlyHighlightOnValue, variant = props.variant == 'horizontal' and 'vertical' or nil, - gameData = { - asGame = match.asGame, - gameIds = match.asGameIndexes, - map = match.map, - mapDisplayName = match.extradata and match.extradata.displayname or nil - } + gameData = match.gameData } end) From a94780fe71b3bc63d3ecf1eb81b900cdb796f1ae Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 9 Jul 2026 12:44:00 +0200 Subject: [PATCH 2/5] fix adjustMatch --- lua/wikis/commons/MatchTicker/Controller.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lua/wikis/commons/MatchTicker/Controller.lua b/lua/wikis/commons/MatchTicker/Controller.lua index 5ad48e77bb7..dd61f3b349e 100644 --- a/lua/wikis/commons/MatchTicker/Controller.lua +++ b/lua/wikis/commons/MatchTicker/Controller.lua @@ -497,19 +497,19 @@ end --- Will only switch if enteredOpponentOnLeft is enabled AND there are exactly 2 opponents ---@private ----@param match MatchGroupUtilMatch +---@param match {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?} ---@param config MatchTickerConfig function MatchTickerController.adjustMatch(match, config) - if not config.enteredOpponentOnLeft or #match.opponents ~= 2 then + if not config.enteredOpponentOnLeft or #match.match.opponents ~= 2 then return end local opponentNames = Array.extend({config.player}, config.teamPages) if --check for the name value - Table.includes(opponentNames, ((match.opponents[2].name or ''):gsub(' ', '_'))) + Table.includes(opponentNames, ((match.match.opponents[2].name or ''):gsub(' ', '_'))) --check inside match2players too for the player value - or config.player and Table.any(match.opponents[2].players, function(_, playerData) + or config.player and Table.any(match.match.opponents[2].players, function(_, playerData) return (playerData.pageName or ''):gsub(' ', '_') == config.player end) then MatchTickerController.switchOpponents(match) @@ -518,17 +518,17 @@ end --- Will only switch if there are exactly 2 opponents ---@private ----@param match MatchGroupUtilMatch +---@param match {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?} function MatchTickerController.switchOpponents(match) - if #match.opponents ~= 2 then + if #match.match.opponents ~= 2 then return end - local winner = tonumber(match.winner) or 0 - match.winner = winner == 1 and 2 + local winner = tonumber(match.match.winner) or 0 + match.match.winner = winner == 1 and 2 or winner == 2 and 1 - or match.winner + or match.match.winner - match.opponents[1], match.opponents[2] = match.opponents[2], match.opponents[1] + match.match.opponents[1], match.match.opponents[2] = match.match.opponents[2], match.match.opponents[1] end --- Fetches region of a tournament From 2e8cb765a80694a3badcd5a832c10d28978a8b04 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 9 Jul 2026 13:31:32 +0200 Subject: [PATCH 3/5] revert to how it was before, with anno improvement --- lua/wikis/commons/MatchTicker/Controller.lua | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lua/wikis/commons/MatchTicker/Controller.lua b/lua/wikis/commons/MatchTicker/Controller.lua index dd61f3b349e..e0796f2f426 100644 --- a/lua/wikis/commons/MatchTicker/Controller.lua +++ b/lua/wikis/commons/MatchTicker/Controller.lua @@ -418,27 +418,24 @@ function MatchTickerController.expandGamesOfMatch(match, config) return {{match = match}} end - local gamesToExpand = Array.filter(match.games, function(game) + ---@type {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] + local expandedGames = Array.map(match.games, function(game, gameIndex) if config.recent and Logic.isEmpty(game.winner) then - return false + return end if (config.upcoming or config.ongoing) and Logic.isNotEmpty(game.winner) then - return false + return end if not game.date then - return false + return end if not config.upcoming and NOW < game.date then - return false + return end if not (config.ongoing or config.recent) and NOW >= game.date then - return false + return end - return true - end) - - local expandedGames = Array.map(gamesToExpand, function(game, gameIndex) local gameMatch = Table.copy(match) gameMatch.games = {} From 147fd31738eb134484f891da7d5634fadb415db4 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 9 Jul 2026 13:41:32 +0200 Subject: [PATCH 4/5] adjust --- lua/wikis/commons/MatchTicker/Controller.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wikis/commons/MatchTicker/Controller.lua b/lua/wikis/commons/MatchTicker/Controller.lua index e0796f2f426..1eb5d1a23bf 100644 --- a/lua/wikis/commons/MatchTicker/Controller.lua +++ b/lua/wikis/commons/MatchTicker/Controller.lua @@ -240,7 +240,7 @@ function MatchTickerController.fetchMatches(config) matches = MatchTickerController.sortMatches(matches, config) matches = Array.sub(matches, 1, config.limit) - matches = Array.map(matches, function(match) return MatchTickerController.adjustMatch(match, config) end) + Array.forEach(matches, function(match) return MatchTickerController.adjustMatch(match, config) end) return matches end From 13dc27737d1c9c2fc6b87ca67504b59910b2493d Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 9 Jul 2026 13:44:21 +0200 Subject: [PATCH 5/5] fix --- lua/wikis/commons/MatchTicker/Controller.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lua/wikis/commons/MatchTicker/Controller.lua b/lua/wikis/commons/MatchTicker/Controller.lua index 1eb5d1a23bf..9efe0ad3305 100644 --- a/lua/wikis/commons/MatchTicker/Controller.lua +++ b/lua/wikis/commons/MatchTicker/Controller.lua @@ -238,7 +238,7 @@ function MatchTickerController.fetchMatches(config) return {} end - matches = MatchTickerController.sortMatches(matches, config) + MatchTickerController.sortMatches(matches, config) matches = Array.sub(matches, 1, config.limit) Array.forEach(matches, function(match) return MatchTickerController.adjustMatch(match, config) end) @@ -474,10 +474,9 @@ end ---@private ---@param matches {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] ---@param config MatchTickerConfig ----@return {match: MatchGroupUtilMatch, gameData: MatchTickerGameData?}[] function MatchTickerController.sortMatches(matches, config) local reverse = config.recent and true or false - return Array.sortBy(matches, FnUtil.identity, function (a, b) + Array.sortInPlaceBy(matches, FnUtil.identity, function (a, b) local aDate, bDate = a.match.date, b.match.date if aDate ~= bDate then if reverse then @@ -485,8 +484,8 @@ function MatchTickerController.sortMatches(matches, config) end return bDate > aDate end - if a.match.match2id ~= b.match.match2id then - return a.match.match2id < b.match.match2id + if a.match.matchId ~= b.match.matchId then + return a.match.matchId < b.match.matchId end return (((a.gameData or {}).gameIds or {})[1] or 0) < (((b.gameData or {}).gameIds or {})[1] or 0) end)