Skip to content

Commit

Permalink
feat: track failed tile levels
Browse files Browse the repository at this point in the history
Track failed tile levels to avoid repeating the
same request multiple times.
Retry tile level API request once on error to
be more resilient.
  • Loading branch information
oscarlorentzon committed Nov 17, 2023
1 parent 312f14b commit a7c1f00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tile/TextureProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class TextureProvider {
private readonly _store: TileStore;
private readonly _subscriptions: Map<string, Subscription>;
private readonly _urlSubscriptions: Map<number, Subscription>;
private readonly _failedLevels: Set<number>;
private readonly _renderedLevel: Set<string>;
private readonly _rendered: Map<string, TileCoords3D>;

Expand Down Expand Up @@ -125,6 +126,7 @@ export class TextureProvider {
this._rendered = new Map();
this._subscriptions = new Map();
this._urlSubscriptions = new Map();
this._failedLevels = new Set();
this._loader = loader;
this._store = store;

Expand Down Expand Up @@ -334,6 +336,10 @@ export class TextureProvider {
* retrieve.
*/
private _fetchTiles(level: number, tiles: TileCoords2D[]): void {
if (this._failedLevels.has(level)) {
return;
}

const urls$ = this._store.hasURLLevel(level) ?
observableOf(undefined) :
this._loader
Expand All @@ -343,6 +349,11 @@ export class TextureProvider {
if (!this._store.hasURLLevel(level)) {
this._store.addURLs(level, ents);
}
if (this._failedLevels.size > 0) {
// tslint:disable-next-line:no-console
console.debug(`Tile URL fetch succeeded for level ${level}, resetting failed levels ${[...this._failedLevels.keys()]}`);
this._failedLevels.clear();
}
}));

const subscription = urls$.subscribe(
Expand Down Expand Up @@ -382,6 +393,7 @@ export class TextureProvider {
this._urlSubscriptions.delete(level);
},
(error: Error): void => {
this._failedLevels.add(level);
this._urlSubscriptions.delete(level);
// tslint:disable-next-line:no-console
console.debug(error);
Expand Down
2 changes: 2 additions & 0 deletions src/tile/TileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
map,
publish,
refCount,
retry,
} from "rxjs/operators";
import { APIWrapper } from "../api/APIWrapper";
import { ImageTileEnt } from "../api/ents/ImageTileEnt";
Expand Down Expand Up @@ -96,6 +97,7 @@ export class TileLoader {
const urls$ = this._api
.getImageTiles$(request)
.pipe(
retry(1),
map(contract => contract.node),
finalize(
() => {
Expand Down

0 comments on commit a7c1f00

Please sign in to comment.