Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: Compare regexes as strings when checking imagery blocklists #8860

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions modules/renderer/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function rendererBackground(context) {
const dispatch = d3_dispatch('change');
const detected = utilDetect();
const baseLayer = rendererTileLayer(context).projection(context.projection);
let _checkedBlocklists = [];
let _isValid = true;
let _overlayLayers = [];
let _brightness = 1;
Expand Down Expand Up @@ -271,7 +272,6 @@ export function rendererBackground(context) {
context.history().photoOverlaysUsed(photoOverlaysUsed);
};

let _checkedBlocklists;

background.sources = (extent, zoom, includeCurrent) => {
if (!_imageryIndex) return []; // called before init()?
Expand All @@ -282,16 +282,17 @@ export function rendererBackground(context) {

const currSource = baseLayer.source();

// Recheck blocked sources only if we detect new blocklists pulled from the OSM API.
const osm = context.connection();
const blocklists = osm && osm.imageryBlocklists();
const blocklists = (osm && osm.imageryBlocklists()) || [];
const blocklistChanged = (blocklists.length !== _checkedBlocklists.length) ||
blocklists.some((regex, index) => String(regex) !== _checkedBlocklists[index]);

if (blocklists && blocklists !== _checkedBlocklists) {
if (blocklistChanged) {
_imageryIndex.backgrounds.forEach(source => {
source.isBlocked = blocklists.some(function(blocklist) {
return blocklist.test(source.template());
});
source.isBlocked = blocklists.some(regex => regex.test(source.template()));
});
_checkedBlocklists = blocklists;
_checkedBlocklists = blocklists.map(regex => String(regex));
}

return _imageryIndex.backgrounds.filter(source => {
Expand Down