ApiResponseCache: Support redirects data processing

If the mediawiki Api pass redirects as true, the response will have
redirect data. ApiResponseCache ignores it now. This commit adds
support for processing that and set in the cache.

Change-Id: If4f8c9b6719c123b31d852eb71f06a79cc0f7917
This commit is contained in:
Santhosh Thottingal 2018-05-23 16:18:01 +05:30
parent 5330e42dc7
commit 27d0634abf
No known key found for this signature in database
GPG key ID: 523DE28934DA0B5A

View file

@ -160,10 +160,11 @@ ve.init.mw.ApiResponseCache.prototype.processQueue = function () {
}
function processResult( data ) {
var pageid, page, processedPage,
var i, pageid, page, processedPage, redirects,
pages = ( data.query && data.query.pages ) || data.pages,
processed = {};
redirects = data.query.redirects || [];
if ( pages ) {
for ( pageid in pages ) {
page = pages[ pageid ];
@ -172,6 +173,13 @@ ve.init.mw.ApiResponseCache.prototype.processQueue = function () {
processed[ page.title ] = processedPage;
}
}
for ( i = 0; i < redirects.length; i++ ) {
// Locate the title in redirects, if any.
if ( redirects[ i ].to === page.title ) {
processed[ redirects[ i ].from ] = processedPage;
break;
}
}
cache.set( processed );
}
}