mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
Merge "Revert "Cache image scalable promises by filename""
This commit is contained in:
commit
424c4e4764
|
@ -46,16 +46,6 @@ OO.inheritClass( ve.dm.MWImageNode, ve.dm.GeneratedContentNode );
|
||||||
|
|
||||||
OO.mixinClass( ve.dm.MWImageNode, ve.dm.ResizableNode );
|
OO.mixinClass( ve.dm.MWImageNode, ve.dm.ResizableNode );
|
||||||
|
|
||||||
/* Static Properties */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache the scalable promises to make sure that we only make one
|
|
||||||
* API request per image.
|
|
||||||
*
|
|
||||||
* @property {Object}
|
|
||||||
*/
|
|
||||||
ve.dm.MWImageNode.static.promiseCache = {};
|
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,36 +167,28 @@ ve.dm.MWImageNode.prototype.getScalablePromise = function () {
|
||||||
// On the first call set off an async call to update the scalable's
|
// On the first call set off an async call to update the scalable's
|
||||||
// original dimensions from the API.
|
// original dimensions from the API.
|
||||||
if ( !this.scalablePromise ) {
|
if ( !this.scalablePromise ) {
|
||||||
// Check if the promise is already cached
|
this.scalablePromise = ve.init.mw.Target.static.apiRequest(
|
||||||
if ( !ve.dm.MWImageNode.static.promiseCache[this.getFilename()] ) {
|
{
|
||||||
this.scalablePromise = ve.init.mw.Target.static.apiRequest(
|
'action': 'query',
|
||||||
{
|
'prop': 'imageinfo',
|
||||||
'action': 'query',
|
'indexpageids': '1',
|
||||||
'prop': 'imageinfo',
|
'iiprop': 'size|mediatype',
|
||||||
'indexpageids': '1',
|
'titles': this.getFilename()
|
||||||
'iiprop': 'size|mediatype',
|
},
|
||||||
'titles': this.getFilename()
|
{ 'type': 'POST' }
|
||||||
},
|
).then( ve.bind( function ( response ) {
|
||||||
{ 'type': 'POST' }
|
var page = response.query && response.query.pages[response.query.pageids[0]],
|
||||||
).then( ve.bind( function ( response ) {
|
info = page && page.imageinfo && page.imageinfo[0];
|
||||||
var page = response.query && response.query.pages[response.query.pageids[0]],
|
|
||||||
info = page && page.imageinfo && page.imageinfo[0];
|
|
||||||
|
|
||||||
if ( info ) {
|
if ( info ) {
|
||||||
this.getScalable().setOriginalDimensions( {
|
this.getScalable().setOriginalDimensions( {
|
||||||
'width': info.width,
|
'width': info.width,
|
||||||
'height': info.height
|
'height': info.height
|
||||||
} );
|
} );
|
||||||
// Update media type
|
// Update media type
|
||||||
this.mediaType = info.mediatype;
|
this.mediaType = info.mediatype;
|
||||||
}
|
}
|
||||||
}, this ) ).promise();
|
}, this ) ).promise();
|
||||||
// Cache the promise
|
|
||||||
ve.dm.MWImageNode.static.promiseCache[this.getFilename()] = this.scalablePromise;
|
|
||||||
} else {
|
|
||||||
// If there is a promise for this image in cache, retrieve it
|
|
||||||
this.scalablePromise = ve.dm.MWImageNode.static.promiseCache[this.getFilename()];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this.scalablePromise;
|
return this.scalablePromise;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue