From ad9bdcda3672721670a878b10c3d7e9779f5bb7c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 3 Mar 2021 18:10:41 -0500 Subject: [PATCH] skip fetch --- .../tiled_vector_layer/tiled_vector_layer.tsx | 21 ++++++++++++------- .../public/classes/util/can_skip_fetch.ts | 21 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx index 477b17ae03d7b..c6b345882f537 100644 --- a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx @@ -23,6 +23,7 @@ import { VectorSourceRequestMeta, } from '../../../../common/descriptor_types'; import { MVTSingleLayerVectorSourceConfig } from '../../sources/mvt_single_layer_vector_source/types'; +import { canSkipSourceUpdate } from '../../util/can_skip_fetch'; export class TiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; @@ -68,18 +69,22 @@ export class TiledVectorLayer extends VectorLayer { this._style as IVectorStyle ); const prevDataRequest = this.getSourceDataRequest(); - - const templateWithMeta = await this._source.getUrlTemplateWithMeta(searchFilters); + const dataRequest = await this._source.getUrlTemplateWithMeta(searchFilters); if (prevDataRequest) { const data: MVTSingleLayerVectorSourceConfig = prevDataRequest.getData() as MVTSingleLayerVectorSourceConfig; if (data) { - const canSkipBecauseNoChanges = + const noChangesInSourceState: boolean = data.layerName === this._source.getLayerName() && data.minSourceZoom === this._source.getMinZoom() && - data.maxSourceZoom === this._source.getMaxZoom() && - data.urlTemplate === templateWithMeta.urlTemplate; - - if (canSkipBecauseNoChanges) { + data.maxSourceZoom === this._source.getMaxZoom(); + const noChangesInSearchState: boolean = await canSkipSourceUpdate({ + considerSpatialParameters: false, + source: this.getSource(), + prevDataRequest, + nextMeta: searchFilters, + }); + const canSkip = noChangesInSourceState && noChangesInSearchState; + if (canSkip) { return null; } } @@ -87,7 +92,7 @@ export class TiledVectorLayer extends VectorLayer { startLoading(SOURCE_DATA_REQUEST_ID, requestToken, searchFilters); try { - stopLoading(SOURCE_DATA_REQUEST_ID, requestToken, templateWithMeta, {}); + stopLoading(SOURCE_DATA_REQUEST_ID, requestToken, dataRequest, {}); } catch (error) { onLoadError(SOURCE_DATA_REQUEST_ID, requestToken, error.message); } diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts index 1b2fae413d909..361fb442af7c9 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts @@ -55,10 +55,12 @@ export async function canSkipSourceUpdate({ source, prevDataRequest, nextMeta, + considerSpatialParameters = true, }: { source: ISource; prevDataRequest: DataRequest | undefined; nextMeta: DataMeta; + considerSpatialParameters: boolean; }): Promise { const timeAware = await source.isTimeAware(); const refreshTimerAware = await source.isRefreshTimerAware(); @@ -70,10 +72,10 @@ export async function canSkipSourceUpdate({ if ( !timeAware && !refreshTimerAware && - !extentAware && + !(extentAware && considerSpatialParameters) && !isFieldAware && !isQueryAware && - !isGeoGridPrecisionAware + !(isGeoGridPrecisionAware && considerSpatialParameters) ) { return !!prevDataRequest && prevDataRequest.hasDataOrRequestInProgress(); } @@ -132,13 +134,16 @@ export async function canSkipSourceUpdate({ } let updateDueToPrecisionChange = false; - if (isGeoGridPrecisionAware) { - updateDueToPrecisionChange = !_.isEqual(prevMeta.geogridPrecision, nextMeta.geogridPrecision); - } - let updateDueToExtentChange = false; - if (extentAware) { - updateDueToExtentChange = updateDueToExtent(prevMeta, nextMeta); + + if (considerSpatialParameters) { + if (isGeoGridPrecisionAware) { + updateDueToPrecisionChange = !_.isEqual(prevMeta.geogridPrecision, nextMeta.geogridPrecision); + } + + if (extentAware) { + updateDueToExtentChange = updateDueToExtent(prevMeta, nextMeta); + } } const updateDueToSourceMetaChange = !_.isEqual(prevMeta.sourceMeta, nextMeta.sourceMeta);