User:Bosco/Unsigned helper.js: Difference between revisions

From Test Wiki
Content deleted Content added
dummy edit: `findMaxIndex` was originally added in Special:Diff/1236106652 as protection against infinite recursion, which was caused by buggy interval loading
add code comments
Line 41: Line 41:
}
}


/**
* Batch size for {@link LazyRevisionIdsLoader}.
*/
const LAZY_REVISION_LOADING_INTERVAL = 50;
const LAZY_REVISION_LOADING_INTERVAL = 50;


/**
/**
* Lazily loads revision IDs for a page.
* Lazily loads revision IDs for a page. The loading is done linearly,
* in batches of the size of {@link LAZY_REVISION_LOADING_INTERVAL}.
* This is relatively fast because we are not loading the heavy contents
* of the page, only the metadata.
* Gives zero-indexed access to the revisions. Zeroth revision is the newest revision.
* Gives zero-indexed access to the revisions. Zeroth revision is the newest revision.
*/
*/
Line 217: Line 223:


/**
/**
* Lazily loads full revisions (wikitext, user, revid, tags, edit summary, etc) for a page.
* Lazily loads full revisions (full wikitext and metadata) for a page.
* Gives zero-indexed access to the revisions. Zeroth revision is the newest revision.
* Gives zero-indexed access to the revisions. Zeroth revision is the newest revision.
* Loaded revisions are cached to speed up consecutive requests about the
* same page.
*/
*/
class LazyFullRevisionsLoader {
class LazyFullRevisionsLoader {
Line 334: Line 342:
}
}


/**
* Uses an exponential initial search followed by a binary search to find
* a snippet of text, which was added to the page.
*/
async findRevisionWhenTextAdded(text, startIndex) {
async findRevisionWhenTextAdded(text, startIndex) {
info(`findRevisionWhenTextAdded(startIndex=${startIndex}): searching for '${text}'`);
info(`findRevisionWhenTextAdded(startIndex=${startIndex}): searching for '${text}'`);
Line 360: Line 372:
const candidateFullRevision = await this.#contentLoader.loadContent(candidateIndex);
const candidateFullRevision = await this.#contentLoader.loadContent(candidateIndex);
if (candidateFullRevision?.slots?.main?.content == undefined) {
if (candidateFullRevision?.slots?.main?.content == undefined) {
/*
* TODO can we distinguish between
* - `candidateIndex` is out of bounds of the history
* vs
* - `candidateIndex` is obscured from current user ([[WP:REVDEL]] or [[WP:SUPPRESS]])
* ?
*/
warn('testFunc: Cannot load the content for candidateIndex = ' + candidateIndex);
warn('testFunc: Cannot load the content for candidateIndex = ' + candidateIndex);
return undefined;
return undefined;