jenkins-bot has submitted this change and it was merged.
Change subject: Request data only once
......................................................................
Request data only once
Prevents multiple maps from loading the same data multiple times
This patch also paves way to the future parallel retrieval
of multiple types of external data (geoshapes, web pages)
Bug: T138739
Change-Id: I223f8e528504bee08adbd4bcb0c30f48e01d265f
---
M modules/live/MWMap.js
1 file changed, 24 insertions(+), 8 deletions(-)
Approvals:
JGirault: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/live/MWMap.js b/modules/live/MWMap.js
index 8f4f985..44e0f30 100644
--- a/modules/live/MWMap.js
+++ b/modules/live/MWMap.js
@@ -188,16 +188,32 @@
*/
function getMapGroupData( overlays ) {
var deferred = $.Deferred(),
- groupsLoaded = mw.config.get( 'wgKartographerLiveData'
) || {},
- groupsToLoad = [];
+ groupsLoaded = mw.config.get( 'wgKartographerLiveData'
),
+ groupsToLoad = [],
+ promises = [];
+ if ( !groupsLoaded ) {
+ // Keep the reference to groupsLoaded, as it shouldn't
change again
+ groupsLoaded = {};
+ mw.config.set( 'wgKartographerLiveData', groupsLoaded );
+ }
+
+ // For each requested layer, make sure it is loaded or is
promised to be loaded
$( overlays ).each( function ( key, value ) {
- if ( !( value in groupsLoaded ) ) {
+ var data = groupsLoaded[ value ];
+ if ( data === undefined ) {
groupsToLoad.push( value );
+ // Once loaded, this value will be replaced
with the received data
+ groupsLoaded[ value ] = deferred.promise();
+ } else if ( data !== null && $.isFunction( data.then )
) {
+ promises.push( data );
}
} );
- if ( !groupsToLoad.length ) {
+ if ( groupsToLoad.length ) {
+ promises.push( deferred.promise() );
+ }
+ if ( !promises.length ) {
return deferred.resolve( groupsLoaded ).promise();
}
@@ -210,14 +226,14 @@
} ).done( function ( data ) {
var rawMapData = data.query.pages[ 0 ].mapdata,
mapData = rawMapData && JSON.parse( rawMapData
) || {};
-
$.extend( groupsLoaded, mapData );
- mw.config.set( 'wgKartographerLiveData', groupsLoaded );
-
deferred.resolve( groupsLoaded );
} );
- return deferred.promise();
+ return $.when.apply( $, promises ).then( function () {
+ // All pending promises are done
+ return groupsLoaded;
+ } ).promise();
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/296219
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I223f8e528504bee08adbd4bcb0c30f48e01d265f
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: JGirault <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits