local p = {}
-- Table to store local cached results during this execution
local cache = {}
-- Function to get the number of works
function p.getWorkCount(frame)
local category = frame.args.category or ''
if category == '' then return "0 works" end
-- Check if we already have the result for this category in local cache
if cache[category] then
return cache[category]
end
-- Perform the expensive call to get the number of pages in the category
local pages = mw.site.stats.pagesInCategory(category)
-- Format the result
local result = ''
if tonumber(pages) == 1 then
result = "1 work"
else
result = pages .. " works"
end
-- Store the result in the local cache
cache[category] = result
return result
end
function p.main(frame)
return p.getWorkCount(frame)
end
return p