User:Bosco/Unsigned helper.js: Difference between revisions
From Test Wiki
Content deleted Content added
LazyRevisionIdsLoader#loadIntervalsRecursive: fix logic of checking `response.batchcomplete`. LazyRevisionIdsLoader#loadInterval: fix code of getting `.rvcontinue` from `this.#historyIntervalPromises` |
LazyRevisionIdsLoader#loadIntervalsRecursive: restore the stopper when .batchcomplete==true is returned from API, but we haven't found `targetIndex` yet |
||
| Line 88: | Line 88: | ||
async #loadIntervalsRecursive(startIndex, targetIndex, rvcontinue) { |
async #loadIntervalsRecursive(startIndex, targetIndex, rvcontinue) { |
||
const logMsgPrefix = `#loadIntervalsRecursive(${startIndex}, ${targetIndex}, '${rvcontinue}')`; |
|||
return new Promise(async (resolve, reject) => { |
return new Promise(async (resolve, reject) => { |
||
// reference documentation: https://en.wikipedia.org/w/api.php?action=help&modules=query%2Brevisions |
// reference documentation: https://en.wikipedia.org/w/api.php?action=help&modules=query%2Brevisions |
||
| Line 103: | Line 104: | ||
intervalQuery.rvcontinue = rvcontinue; |
intervalQuery.rvcontinue = rvcontinue; |
||
} |
} |
||
debug( |
debug(`${logMsgPrefix} Q =`, intervalQuery); |
||
this.#api.get(intervalQuery).then(async (response) => { |
this.#api.get(intervalQuery).then(async (response) => { |
||
try { |
try { |
||
// debug( |
// debug(`${logMsgPrefix} R =`, response); |
||
const interval = this.#createIntervalFromResponse(response); |
const interval = this.#createIntervalFromResponse(response); |
||
this.#historyIntervalPromises[startIndex] = Promise.resolve(interval); |
this.#historyIntervalPromises[startIndex] = Promise.resolve(interval); |
||
| Line 114: | Line 115: | ||
return; |
return; |
||
} |
} |
||
if (interval.batchcomplete) { |
|||
| ⚫ | |||
// reached the end of batch loading => cannot ask for one more |
|||
// for convenience, fill the rest of the array with undefined |
|||
for (let i = startIndex + 1; i <= targetIndex; i++) { |
|||
this.#historyIntervalPromises[i] = Promise.resolve(undefined); |
|||
} |
|||
info(`${logMsgPrefix}: This is the last batch returned by MediaWiki`); |
|||
if (targetIndex <= startIndex) { |
|||
error(`${logMsgPrefix}: something went very wrong`); |
|||
} |
|||
resolve(undefined); |
|||
return; |
|||
} |
|||
| ⚫ | |||
const ignored = await this.#loadIntervalsRecursive(startIndex + 1, targetIndex, interval.rvcontinue); |
const ignored = await this.#loadIntervalsRecursive(startIndex + 1, targetIndex, interval.rvcontinue); |
||
if (this.#historyIntervalPromises[targetIndex] == undefined) { |
if (this.#historyIntervalPromises[targetIndex] == undefined) { |
||
| Line 176: | Line 190: | ||
try { |
try { |
||
const interval = await this.#loadInterval(intervalIndex); |
const interval = await this.#loadInterval(intervalIndex); |
||
debug(`loadRevision: loaded the interval#${intervalIndex} with revisions: (length=${interval?.revisions?.length})`); |
debug(`loadRevision: loaded the interval#${intervalIndex} with revisions: (length=${interval?.revisions?.length}) ${this.#revisionsToString(interval?.revisions)}`); |
||
// debug(`loadRevision: loaded the interval#${intervalIndex} with revisions: (length=${interval?.revisions?.length}) ${this.#revisionsToString(interval?.revisions)}`); |
|||
if (interval == undefined) { |
if (interval == undefined) { |
||
resolve(undefined); |
resolve(undefined); |
||
| Line 315: | Line 328: | ||
async #findMaxIndex() { |
async #findMaxIndex() { |
||
info('#findMaxIndex: this.#progressCallback = ', this.#progressCallback); |
|||
return exponentialSearch(0, null, 1, async (candidateIndex, progressInfo) => { |
return exponentialSearch(0, null, 1, async (candidateIndex, progressInfo) => { |
||
this.#progressCallback(progressInfo + ' (max search)'); |
this.#progressCallback(progressInfo + ' (max search)'); |
||
| Line 326: | Line 340: | ||
async findRevisionWhenTextAdded(text, startIndex) { |
async findRevisionWhenTextAdded(text, startIndex) { |
||
info( |
info(`findRevisionWhenTextAdded(startIndex=${startIndex}): searching for '${text}'`); |
||
return new Promise(async (resolve, reject) => { |
return new Promise(async (resolve, reject) => { |
||
try { |
try { |
||