Fix too many item lookups on items will silly amounts of authors
This commit is contained in:
parent
43bf989f91
commit
b2ab54ccb4
1 changed files with 19 additions and 4 deletions
|
|
@ -107,6 +107,8 @@ end
|
|||
-- function to fetch a value to display
|
||||
local function makelink(v, out, link, maxpos, wdl, namestyle)
|
||||
local label
|
||||
local max_authors_displayed = 10 -- TODO: this is probably in CS1 config somewhere
|
||||
local item_lookup = false
|
||||
if v.mainsnak.snaktype == "value" then
|
||||
if v.mainsnak.datatype == "wikibase-item" then
|
||||
local qnumber = v.mainsnak.datavalue.value.id
|
||||
|
|
@ -123,12 +125,15 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
|
|||
first_names = v.qualifiers.P9687[1].datavalue.value
|
||||
end
|
||||
-- Otherwise, get last name, first name(s) from author item properties
|
||||
last_name = last_name or getValue({"P734", qid=qnumber, maxvals=1, ps=2})
|
||||
first_names = first_names or getValue({"P735", qid=qnumber, maxvals=0, ps=2})
|
||||
if first_names then
|
||||
first_names = getStyledNames(first_names, namestyle)
|
||||
-- but this requires a getValue WD item lookup for each author, and
|
||||
-- lookups are limited to 500 per page, so do this after we have the
|
||||
-- "series ordinal" order, then only do the first few since there are
|
||||
-- article items out there with 400+ authors(!)
|
||||
if not last_name or not first_names then
|
||||
item_lookup = true
|
||||
end
|
||||
|
||||
-- use object named as for the label
|
||||
if v.qualifiers and v.qualifiers.P1932 then
|
||||
label = v.qualifiers.P1932[1].datavalue.value -- "object named as"
|
||||
else
|
||||
|
|
@ -145,6 +150,16 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
|
|||
position = tonumber(v.qualifiers.P1545[1].datavalue.value)
|
||||
end
|
||||
maxpos = math.max(maxpos, position)
|
||||
|
||||
-- now try determining first/last names with item lookup, if needed
|
||||
if item_lookup and position <= max_authors_displayed then
|
||||
last_name = last_name or getValue({"P734", qid=qnumber, maxvals=1, ps=2})
|
||||
first_names = first_names or getValue({"P735", qid=qnumber, maxvals=0, ps=2})
|
||||
end
|
||||
if first_names then
|
||||
first_names = getStyledNames(first_names, namestyle)
|
||||
end
|
||||
|
||||
if sitelink then
|
||||
-- just the plain name,
|
||||
-- but keep a record of the links, using the same index
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue