Skip to content

Commit

Permalink
skip fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Mar 3, 2021
1 parent b33ea36 commit ad9bdcd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,26 +69,30 @@ 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;
}
}
}

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);
}
Expand Down
21 changes: 13 additions & 8 deletions x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ export async function canSkipSourceUpdate({
source,
prevDataRequest,
nextMeta,
considerSpatialParameters = true,
}: {
source: ISource;
prevDataRequest: DataRequest | undefined;
nextMeta: DataMeta;
considerSpatialParameters: boolean;
}): Promise<boolean> {
const timeAware = await source.isTimeAware();
const refreshTimerAware = await source.isRefreshTimerAware();
Expand All @@ -70,10 +72,10 @@ export async function canSkipSourceUpdate({
if (
!timeAware &&
!refreshTimerAware &&
!extentAware &&
!(extentAware && considerSpatialParameters) &&
!isFieldAware &&
!isQueryAware &&
!isGeoGridPrecisionAware
!(isGeoGridPrecisionAware && considerSpatialParameters)
) {
return !!prevDataRequest && prevDataRequest.hasDataOrRequestInProgress();
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ad9bdcd

Please sign in to comment.