Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Number of works: Difference between revisions

From ProleWiki, the proletarian encyclopedia
No edit summary
(reverted to july 2023 version)
Tag: Manual revert
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Table to store local cached results during this execution
local cache = {}
-- Function to get the number of works
function p.getWorkCount(frame)
function p.getWorkCount(frame)
     local category = frame.args.category or ''
     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)
     local pages = mw.site.stats.pagesInCategory(category)
 
      
     -- Format the result
    local result = ''
     if tonumber(pages) == 1 then
     if tonumber(pages) == 1 then
         result = "1 work"
         return "1 work"
     else
     else
         result = pages .. " works"
         return pages .. " works"
     end
     end
    -- Store the result in the local cache
    cache[category] = result
    return result
end
end



Latest revision as of 15:19, 14 September 2024

local p = {}

function p.getWorkCount(frame)
    local category = frame.args.category or ''
    local pages = mw.site.stats.pagesInCategory(category)
    
    if tonumber(pages) == 1 then
        return "1 work"
    else
        return pages .. " works"
    end
end

function p.main(frame)
    return p.getWorkCount(frame)
end

return p