Skip to content

Commit

Permalink
Introduce MapService's clientId, which is used by mapget to implicitl…
Browse files Browse the repository at this point in the history
…y abort a previous fetch operation.
  • Loading branch information
josephbirkner committed Oct 18, 2024
1 parent 55a9a62 commit d5a05b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
24 changes: 17 additions & 7 deletions erdblick_app/app/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {InfoMessageService} from "./info.service";
import {MAX_ZOOM_LEVEL} from "./feature.search.service";
import {PointMergeService} from "./pointmerge.service";
import {KeyboardService} from "./keyboard.service";
import * as uuid from 'uuid';

/** Expected structure of a LayerInfoItem's coverage entry. */
export interface CoverageRectItem extends Record<string, any> {
Expand Down Expand Up @@ -85,6 +86,7 @@ export class MapService {
public loadedTileLayers: Map<string, FeatureTile>;
private visualizedTileLayers: Map<string, TileVisualization[]>;
private currentFetch: Fetch|null = null;
private currentFetchId: number = 0;
private currentViewport: ViewportProperties;
private currentVisibleTileIds: Set<bigint>;
private currentHighDetailTileIds: Set<bigint>;
Expand All @@ -111,6 +113,7 @@ export class MapService {
} | null = null;
zoomLevel: BehaviorSubject<number> = new BehaviorSubject<number>(0);
statsDialogVisible: boolean = false;
clientId: string = "";

constructor(public styleService: StyleService,
public parameterService: ParametersService,
Expand Down Expand Up @@ -146,6 +149,10 @@ export class MapService {

// Triggered when the user requests to zoom to a map layer.
this.moveToWgs84PositionTopic = new Subject<{x: number, y: number}>();

// Unique client ID which ensures that tile fetch requests from this map-service
// are de-duplicated on the mapget server.
this.clientId = uuid.v4();
}

public async initialize() {
Expand Down Expand Up @@ -503,15 +510,15 @@ export class MapService {
}
}

// Abort previous fetch operation, if it is different from the new one.
// Ensure that the new fetch operation is different from the previous one.
let newRequestBody = JSON.stringify({
requests: requests,
stringPoolOffsets: this.tileParser!.getFieldDictOffsets()
stringPoolOffsets: this.tileParser!.getFieldDictOffsets(),
clientId: this.clientId
});
if (this.currentFetch) {
if (this.currentFetch.bodyJson === newRequestBody)
return;
this.currentFetch.abort();
this.currentFetch = null;
// Clear any unparsed messages from the previous stream.
this.tileStreamParsingQueue = [];
Expand All @@ -526,15 +533,18 @@ export class MapService {
this.tileParser!.reset();

// Launch the new fetch operation
let myFetchId = ++this.currentFetchId;
this.currentFetch = new Fetch(tileUrl)
.withChunkProcessing()
.withMethod("POST")
.withBody(newRequestBody)
.withBufferCallback((message: any, messageType: any) => {
// Schedule the parsing of the newly arrived tile layer,
// but don't do it synchronously to avoid stalling the ongoing
// fetch operation.
this.tileStreamParsingQueue.push([message, messageType]);
// Schedule the parsing of the newly arrived tile layer.
// Ignore the new data, if this fetch operation is not
// the most recent one anymore.
if (myFetchId == this.currentFetchId) {
this.tileStreamParsingQueue.push([message, messageType]);
}
});
this.currentFetch.go();
}
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@ngx-formly/primeng": "^6.3.9",
"@types/jasmine": "~5.1.4",
"@types/js-yaml": "^4.0.9",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"eslint": "^9.9.0",
Expand Down

0 comments on commit d5a05b8

Please sign in to comment.