Module:Franchise/Cache

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

local gameFields = "canonOrder, code, article, shortName, link, display, logo, releaseDate, canonicity, type, graphics, family, remakeOf, supersededBy" local bookFields = "canonOrder, code, article, shortName, link, display, logo, releaseDate, canonicity, type, phraseLink, publisher, authors, basedOn" local tvFields = "canonOrder, code, article, shortName, link, display, logo, releaseDate, canonicity, type" local nonFictionFields = "code, article, shortName, link, display, logo, releaseDate, canonicity, publisher, titles" local groupFields= "code, article, shortName, link, display, logo, releaseDate, canonicity, games"

local games = utilsCargo.query("Games", gameFields, { sortBy = "canonOrder", limit = 200 }) local books = utilsCargo.query("Books", bookFields, { sortBy = "canonOrder" }) local tvShows = utilsCargo.query("TelevisionShows", tvFields, { sortBy = "canonOrder" }) local nonfiction = utilsCargo.query("Nonfiction", nonFictionFields, { sortBy = "releaseDate" }) local groups = utilsCargo.query("GameGroups", groupFields, { sortBy = "releaseDate" }) -- Cargo isn't sorting properly for some reason groups = utilsTable.sortBy(groups, "releaseDate") nonfiction = utilsTable.sortBy(nonfiction, "releaseDate")

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

for _, game in ipairs(games) do	codes[tonumber(game.canonOrder)] = game.code gameCodes[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 gameCodes = utilsTable.compact(gameCodes)

for _, book in ipairs(books) do	if utilsString.notEmpty(book.code) then -- workaround for Cargo bug inserting duplicate rows (but without code) codes[tonumber(book.canonOrder)] = book.code titlesByCode[string.lower(book.code)] = book end end

for _, tvShow in ipairs(tvShows) do	codes[tonumber(tvShow.canonOrder)] = tvShow.code titlesByCode[string.lower(tvShow.code)] = tvShow end

for _, book in ipairs(nonfiction) do	titlesByCode[string.lower(book.code)] = book end

for _, group in ipairs(groups) do	titlesByCode[string.lower(group.code)] = group end

codes.reference = "Data:Franchise" gameCodes.reference = "Data:Franchise"

return { enum = codes, enumGames = gameCodes, games = games, titlesByCode = titlesByCode, remakes = remakes, nonfiction = nonfiction, groups = groups, }