Module:BucketCount

From The Deadlock Wiki
Revision as of 12:21, 28 August 2026 by Kai (talk | contribs) (Kai moved page Module:Bucketcount to Module:BucketCount without leaving a redirect)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:BucketCount/doc

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local bucket_name = mw.text.trim(args[1] or '')
	local select_field = mw.text.trim(args[2] or '')
	local count = 0
	while(true) do
		local b = bucket(bucket_name).select(select_field).limit(5000).offset(count)
		for k, v in pairs(args) do
			if k ~= 1 and k ~= 2 then -- https://runescape.wiki/w/Module:BucketCount?action=edit -- creds to these geezers
				v = mw.text.decode(v) -- {{PAGENAME}} will urlencode apostrophe, so we have to undo it
				if string.sub(k, 1, 1) == '!' then
					k = string.sub(k, 2, #k)
					b.where(bucket.Not({k, v}))	
				else
					b.where(k, v)
				end
					
			end
		end

		local data = b.run()
		count = count + #data
		
		if #data < 5000 then
			return count
		end
	end
end

return p