MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 3,161: | Line 3,161: | ||
// ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
var API = API_BASE.replace(/\/+$/, ''); | var API = API_BASE.replace(/\/+$/, ''); | ||
var mem = {}; | var mem = {}; | ||
var warned = false; | var warned = false; | ||
| Line 3,169: | Line 3,168: | ||
var libraryDown = !LIBRARY_ENABLED; | var libraryDown = !LIBRARY_ENABLED; | ||
// In memory only, for the life of the page. Names used to be kept in | |||
// sessionStorage for six hours, which quietly outlived any correction | |||
// made in the library or on the map page. They now come from the map | |||
// page, which is read once per load, so there is nothing to gain from | |||
// a second cache that can disagree with it. | |||
function cacheGet(id) { return mem[id] || null; } | |||
function cacheSet(id, v) { mem[id] = v; } | |||
function cacheSet(id, v) { | |||
// The library returns camelCase fields; normalise to what the citation | // The library returns camelCase fields; normalise to what the citation | ||
| Line 3,280: | Line 3,270: | ||
function granthaMap() { | function granthaMap() { | ||
if (mapPromise) return mapPromise; | if (mapPromise) return mapPromise; | ||
// Deliberately NOT cached in sessionStorage. It was, for six hours, | |||
try { | // which meant that editing the map page changed nothing for anyone | ||
// whose tab had already read the old one - the exact failure you hit | |||
// while setting this up. mapPromise already collapses it to one | |||
// request per page load, and the browser's own HTTP cache handles | |||
// the rest; a stale map is far more expensive than a small fetch. | |||
try { sessionStorage.removeItem('gr-lib:map'); } catch (e) { } | |||
var url = (window.mw && mw.util && mw.util.getUrl) | var url = (window.mw && mw.util && mw.util.getUrl) | ||
| Line 3,294: | Line 3,284: | ||
.then(function (r) { return r.ok ? r.json() : {}; }) | .then(function (r) { return r.ok ? r.json() : {}; }) | ||
.then(function (m) { | .then(function (m) { | ||
// Either a flat {page: id} object, or {pages | // Either a flat {page: id} object, or {pages, works, | ||
// locators | // locators} when names and division names are recorded too. | ||
m = m || {}; | m = m || {}; | ||
if (!m.pages) m = { pages: m | if (!m.pages) m = { pages: m }; | ||
m.works = m.works || {}; | |||
m.locators = m.locators || {}; | m.locators = m.locators || {}; | ||
try { | try { | ||
catch (e) { } | if (!Object.keys(m.works).length) { | ||
console.info('[grantha] the map page has no "works" section, ' + | |||
'so names must come from the library API. Re-run ' + | |||
'sync_grantha_map.py to embed them.'); | |||
} | |||
} catch (e) { } | |||
return m; | return m; | ||
}) | }) | ||