Module:Franchise/Cache

local utilsCargo = require("Module:UtilsCargo") local utilsString = require("Module:UtilsString") local utilsTable = require("Module:UtilsTable")

local commonFields = {"canonOrder", "code", "shortName", "link", "display", "firstRelease", "canonicity", "type"} local gameFields = utilsTable.concat(commonFields, {"graphics", "family", "remakeOf", "supersededBy"}) local comicFields = utilsTable.concat(commonFields, {"phraseLink", "authors", "basedOn"})

local games = utilsCargo.query("Games2", table.concat(gameFields, ",")) local comics = utilsCargo.query("Comics", table.concat(comicFields, ","))

local codes = {} local titlesByCode = {} local remakes = {}

for _, game in ipairs(games) do	codes[tonumber(game.canonOrder)] = game.code titlesByCode[string.lower(game.code)] = game if utilsString.notEmpty(game.remakeOf) then remakes[string.lower(game.remakeOf)] = utilsTable.concat(remakes[string.lower(game.remakeOf)], game.code) end end for _, comic in ipairs(comics) do	if utilsString.notEmpty(comic.code) then -- workaround for Cargo bug inserting duplicate rows (but without code) codes[tonumber(comic.canonOrder)] = comic.code titlesByCode[string.lower(comic.code)] = comic end end codes.reference = "Data:Franchise"

return { enum = codes, titlesByCode = titlesByCode, remakes = remakes, }