Skip to content

Commit

Permalink
offline tile management fixes (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters authored Jan 3, 2024
1 parent bcf9c3c commit 5464a5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/offlineTilePackages/createTilePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ export async function createTilePackage(packageId: string, client: DBClient) {
} else {
if (response.status < 500) {
failuresWithoutSuccess++;
if (failuresWithoutSuccess > 20) {
if (failuresWithoutSuccess > 2000) {
throw new Error(
`Failed to retrieve tiles ${failuresWithoutSuccess} times without any successes. Last message = ${await response.text()}`
`Failed to retrieve tiles ${failuresWithoutSuccess} times without any successes. Last message = ${await response.text()}. Last url = ${url}`
);
}
} else {
Expand Down
18 changes: 9 additions & 9 deletions packages/client/src/dataLayers/MapContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2533,19 +2533,19 @@ class MapContextManager extends EventEmitter {
offlineTileSimulatorActive: true,
}));
this.updateStyle();
// Using a bunch of undocumented private apis here. See:
// https://github.com/mapbox/mapbox-gl-js/issues/2633#issuecomment-518622682
// TODO: This seems to be out of date with new version of mapbox-gl-js
// Using a bunch of undocumented private apis here to reset tile caches.
// See:
// https://github.com/mapbox/mapbox-gl-js/issues/2633#issuecomment-576050636
// @ts-ignore
const sourceCaches = this.map?.style?._sourceCaches;
await window.caches.delete("mapbox-tiles");
if (sourceCaches) {
// const cache = sourceCaches["other:composite"];
for (const cache of Object.values(sourceCaches)) {
// @ts-ignore
cache.clearTiles();
// @ts-ignore
cache.update(this.map.transform);
for (const cache of Object.values(sourceCaches) as any[]) {
for (const id in cache._tiles) {
cache._tiles[id].expirationTime = Date.now() - 1;
cache._reloadTile(id, "reloading");
}
cache._cache.reset();
}
this.map?.triggerRepaint();
this.map?.resize();
Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/offline/MapTileCacheHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export function handleSimulatorRequest(
if (inCache) {
return fetch(realUrl);
} else {
return new Response("", { status: 500 });
return new Response("Offline tile similator. Tile not in cache.", {
status: 500,
});
}
});
} else {
return fetch(event.request).catch((e) => {
return fetch(realUrl).catch((e) => {
return new Response(e.toString(), { status: 500 });
});
}
Expand Down

0 comments on commit 5464a5a

Please sign in to comment.