implement latlng-to-guid cache
This commit is contained in:
parent
2def40c847
commit
e9bd88fe31
@ -258,6 +258,8 @@ window.Render.prototype.createPortalEntity = function(ent) {
|
||||
data: ent[2]
|
||||
};
|
||||
|
||||
window.pushPortalGuidPositionCache(ent[0], ent[2].latE6, ent[2].lngE6);
|
||||
|
||||
var marker = createMarker(latlng, dataOptions);
|
||||
|
||||
marker.on('click', function() { window.renderPortalDetails(ent[0]); });
|
||||
|
@ -88,7 +88,32 @@ window.findPortalLatLng = function(guid) {
|
||||
|
||||
// no luck finding portal lat/lng
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
(function() {
|
||||
var cache = {};
|
||||
var GC_LIMIT = 5000; // run garbage collector when cache has more that 5000 items
|
||||
var GC_KEEP = 4000; // keep the 4000 most recent items
|
||||
|
||||
window.findPortalGuidByPositionE6 = function(latE6, lngE6) {
|
||||
var item = cache[latE6+","+lngE6];
|
||||
if(!item) return null;
|
||||
return item[0];
|
||||
};
|
||||
|
||||
window.pushPortalGuidPositionCache = function(guid, latE6, lngE6) {
|
||||
cache[latE6+","+lngE6] = [guid, Date.now()];
|
||||
|
||||
if(Object.keys(cache).length > GC_LIMIT) {
|
||||
Object.keys(cache) // get all latlngs
|
||||
.map(function(latlng) { return [latlng, cache[latlng][1]]; }) // map them to [latlng, timestamp]
|
||||
.sort(function(a,b) { return b[1] - a[1]; }) // sort them
|
||||
.slice(GC_KEEP) // drop the MRU
|
||||
.forEach(function(item) { delete cache[item[0]] }); // delete the rest
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
// get the AP gains from a portal, based only on the brief summary data from portals, links and fields
|
||||
|
Loading…
x
Reference in New Issue
Block a user