全站通知:

模块:Grangeptsrow

来自星露谷物语维基
跳到导航 跳到搜索
作用

该模块用于星露谷展览会农庄展览页面,主要用作类别分一栏下分数明细表的缓存和输出。
使用该模块能够避免因 lua 脚本运行缓慢,进而导致运行超时出现报错。

[ 查看 | 编辑 | 历史 | 刷新 ]上述文档的内容来自模块:Grangeptsrow/doc
local cache = require "mw.ext.LuaCache"
local KEY_PREFIX = "Module:Grangeptsrow"
local EXP_TIME = 172800
local p = {}

local function expandTemplate(args)
	local templateArgs = {}
    for key, value in pairs(args) do
	    if value ~= "" then
	        templateArgs[key] = value
	    end
    end
    return mw.getCurrentFrame():expandTemplate{
        title = 'Grangeptsrow/Base',
        args = {
            templateArgs[1],
            templateArgs[2],
            templateArgs[3],
            templateArgs[4],
            qualities = templateArgs['qualities'],
            item = templateArgs['item'],
        }
    }
end

function p.render(frame)
    local args = frame.args
    local cacheKey = KEY_PREFIX .. "|" .. args[1] .. "|" .. args[2] .. "|" .. args[3] .. "|" .. args[4] .. "|" .. (args['qualities'] or "") .. "|" .. (args['item'] or "")
    if cache.get(cacheKey) then
    	local result = cache.get(cacheKey)
        return result
    end
    local result = expandTemplate(args)
    cache.set(cacheKey, result, EXP_TIME)
    return result
end

function p.expand(frame)
    -- local text = frame.args[1] or ''
    local cacheKey = '展览会缓存'
    if cache.get(cacheKey) then
    	local result = cache.get(cacheKey)
        return result
    end
    local text = mw.title.new("星露谷展览会/类别分"):getContent()
    local expanded = frame:preprocess(text)
    cache.set(cacheKey, expanded, EXP_TIME)
    return expanded
end

return p