Jump to content

Module:Theosophist authors: Difference between revisions

m
Each of the three lists now queries only its own part of the contents and only the fields it needs: one query over all 7025 entries exceeded the 5 MB post-expand include limit and the lists came out empty
m (Split the author index into three lists: established authors, unidentified signatures and unsigned material; the query now covers every contents entry, not only those with an author)
m (Each of the three lists now queries only its own part of the contents and only the fields it needs: one query over all 7025 entries exceeded the 5 MB post-expand include limit and the lists came out empty)
 
Line 36: Line 36:
end
end


local function fetch(frame)
-- Поля записи: ключ в raw row -> имя свойства. Порядок ORDER совпадает с
-- порядком слотов в Template:Theosophist authors raw row; незапрошенные
-- поля приходят пустыми, но число слотов не меняется.
local PRINTOUT = {
    a = 'author', id = 'ID', t = 'title', v = 'volume', n = 'number',
    pg = 'page', m = 'month', y = 'year', links = 'links to text',
    as = 'author signed',
}
local ORDER = {'a', 'id', 't', 'v', 'n', 'pg', 'm', 'y', 'links', 'as'}
 
local function printouts(want)
    local parts = {}
    for _, key in ipairs(ORDER) do
        if want[key] then
            local one = '|?Theosophist item ' .. PRINTOUT[key] .. '=' .. key
            if key == 'a' then one = one .. '|+sep=' .. AS end
            if key == 'links' then one = one .. '|+sep=; ' end
            table.insert(parts, one)
        end
    end
    return table.concat(parts)
end
 
-- Каждый список запрашивает только свою часть оглавления и только нужные
-- поля: разворот шаблона ограничен 5 МБ на страницу (post-expand include
-- size), и общий запрос по всем 7025 записям с десятью полями в него уже не
-- помещается -- список молча выходит пустым.
local function fetch(frame, condition, want)
    want = want or {}
    want.id = true
     local rows, offset = {}, 0
     local rows, offset = {}, 0
     for batch = 1, 100 do
     for batch = 1, 100 do
         local query = '{{#ask:[[Theosophist item ID::+]]'
         local query = '{{#ask:' .. condition .. printouts(want)
            .. '|?Theosophist item author=a|+sep=' .. AS
            .. '|?Theosophist item ID=id|?Theosophist item title=t'
            .. '|?Theosophist item volume=v|?Theosophist item number=n|?Theosophist item page=pg'
            .. '|?Theosophist item month=m|?Theosophist item year=y'
            .. '|?Theosophist item links to text=links|+sep=; '
            .. '|?Theosophist item author signed=as'
             .. '|mainlabel=-|link=none|headers=hide|named args=yes'
             .. '|mainlabel=-|link=none|headers=hide|named args=yes'
             .. '|format=template|template=Theosophist authors raw row'
             .. '|format=template|template=Theosophist authors raw row'
Line 127: Line 150:
end
end


local function select_rows(frame, kind)
-- Условия запросов. Отбор делает SMW, а не Lua: так в каждый список
    local out = {}
-- попадает только его часть оглавления.
     for _, r in ipairs(fetch(frame)) do
local COND = {
        if kind == 'carded' and has_card(trim(r.a)) then
     -- установленное имя автора есть (карточка или простой текст)
            table.insert(out, r)
    named = '[[Theosophist item author::+]]',
        elseif kind == 'signature' and not has_card(trim(r.a)) and signature(r) ~= '' then
    -- есть печатная подпись, и она не помета неподписанности
            table.insert(out, r)
    signed = '[[Theosophist item author signed::+]] [[Theosophist item author signed::!~*unsigned*]]',
        elseif kind == 'unsigned' and trim(r.as) == UNSIGNED then
    -- помета неподписанности. Точное сравнение с [unsigned] невозможно:
            table.insert(out, r)
    -- квадратные скобки ломают разбор значения в запросе SMW, поэтому
        end
    -- сравниваем по образцу. На 26.11.2026 оба запроса дают одно и то же
     end
    -- число (3813) -- печатных подписей со словом unsigned в журнале нет.
     return out
    unsigned = '[[Theosophist item author signed::~*unsigned*]]',
}
 
local ALL_FIELDS = {a=true, t=true, v=true, n=true, pg=true, m=true, y=true, links=true}
 
local function with(extra)
    local want = {}
    for k, v in pairs(ALL_FIELDS) do want[k] = v end
     for k, v in pairs(extra or {}) do want[k] = v end
     return want
end
end


function p.list(frame)
function p.list(frame)
     local map, order = group(select_rows(frame, 'carded'))
    local rows = {}
    for _, r in ipairs(fetch(frame, COND.named, with())) do
        if has_card(trim(r.a)) then table.insert(rows, r) end
    end
     local map, order = group(rows)
     local out = {}
     local out = {}
     for _, name in ipairs(order) do
     for _, name in ipairs(order) do
Line 168: Line 204:
-- устанавливает. Группируются так же, как авторы с карточками.
-- устанавливает. Группируются так же, как авторы с карточками.
function p.unidentified(frame)
function p.unidentified(frame)
     local map, order = group(select_rows(frame, 'signature'), signature)
     local rows, seen_id = {}, {}
    local function collect(source)
        for _, r in ipairs(source) do
            if not has_card(trim(r.a)) and signature(r) ~= '' and not seen_id[r.id] then
                seen_id[r.id] = true
                table.insert(rows, r)
            end
        end
    end
    -- записи с печатной подписью: нужен и author, чтобы отсеять тех, у кого
    -- карточка уже есть
    collect(fetch(frame, COND.signed, with({as=true})))
    -- записи, где подпись пока лежит простым текстом в поле author; ссылки
    -- на тексты здесь не запрашиваем -- они дороже всего в развороте
    collect(fetch(frame, COND.named, with({links=false})))
    table.sort(rows, function(a, b) return a.id < b.id end)
    local map, order = group(rows, signature)
     local out = {}
     local out = {}
     for _, name in ipairs(order) do
     for _, name in ipairs(order) do
Line 189: Line 241:
-- Группируется по томам, внутри тома -- по ID, то есть по выпускам и страницам.
-- Группируется по томам, внутри тома -- по ID, то есть по выпускам и страницам.
function p.unsigned(frame)
function p.unsigned(frame)
     local rows = select_rows(frame, 'unsigned')
     local rows = fetch(frame, COND.unsigned, with({a=false}))
     table.sort(rows, function(a, b) return a.id < b.id end)
     table.sort(rows, function(a, b) return a.id < b.id end)
     local out, current = {}, nil
     local out, current = {}, nil
Line 205: Line 257:


function p.debug(frame)
function p.debug(frame)
     local rows = fetch(frame)
     local named = #fetch(frame, COND.named, {})
     local carded, signed, unsigned, blank = 0, 0, 0, 0
     local signed = #fetch(frame, COND.signed, {})
     for _, r in ipairs(rows) do
     local unsigned = #fetch(frame, COND.unsigned, {})
        if has_card(trim(r.a)) then carded = carded + 1 end
     return 'author set: ' .. named .. '; printed signature without the unsigned mark: '
        if not has_card(trim(r.a)) and signature(r) ~= '' then signed = signed + 1 end
        .. signed .. '; marked unsigned: ' .. unsigned
        if trim(r.as) == UNSIGNED then unsigned = unsigned + 1 end
        if trim(r.a) == '' and trim(r.as) == '' then blank = blank + 1 end
    end
     return 'Total contents entries: ' .. #rows .. '; with a dictionary entry: ' .. carded
        .. '; signature without an entry: ' .. signed .. '; marked unsigned: ' .. unsigned
        .. '; neither author nor signature recorded: ' .. blank
end
end


return p
return p