forked from Liquipedia/Lua-Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlpdb.lua
More file actions
67 lines (57 loc) · 1.8 KB
/
Copy pathlpdb.lua
File metadata and controls
67 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Lpdb
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
local Lpdb = {}
local _MAXIMUM_QUERY_LIMIT = 5000
-- Executes a mass query.
--[==[
Loops LPDB queries to e.g.
- circumvent the maximum limit of 5000
- use additional filtering (e.g. because LPDB does not support it)
and query so long until a certain amount of elements is found
or additional limitations are reached
example:
local foundMatchIds = {}
local getMatchId = function(match)
if #foundMatchIds < args.matchLimit then
if HeadToHead._fitsAdditionalConditions(args, match) then
table.insert(foundMatchIds, match.match2id)
end
else
return false
end
end
local queryParameters = {
conditions = conditions,
order = 'date ' .. args.order,
limit = _LPDB_QUERY_LIMIT,
query = 'pagename, winner, walkover, finished, date, dateexact, links, '
.. 'bestof, vod, tournament, tickername, shortname, icon, icondark, '
.. 'extradata, match2opponents, match2games, mode, match2id, match2bracketid',
}
Lpdb.executeMassQuery('match2', queryParameters, getMatchId)
return foundMatchIds
]==]
function Lpdb.executeMassQuery(tableName, queryParameters, itemChecker, limit)
queryParameters.offset = queryParameters.offset or 0
queryParameters.limit = queryParameters.limit or _MAXIMUM_QUERY_LIMIT
limit = limit or math.huge
while queryParameters.offset < limit do
queryParameters.limit = math.min(queryParameters.limit, limit - queryParameters.offset)
local lpdbData = mw.ext.LiquipediaDB.lpdb(tableName, queryParameters)
for _, value in ipairs(lpdbData) do
if itemChecker(value) == false then
return
end
end
queryParameters.offset = queryParameters.offset + #lpdbData
if #lpdbData < queryParameters.limit then
break
end
end
end
return Lpdb