chiitiler 1.23.7 → 1.23.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,8 @@ const mapPoolCache = new LRUCache({
12
12
  },
13
13
  });
14
14
  async function getRenderPool(style, cache, mode) {
15
- const cacheKey = JSON.stringify(style);
15
+ // A Map's mode is fixed at creation; tile and static requests cannot share it.
16
+ const cacheKey = `${mode}:${JSON.stringify(style)}`;
16
17
  const pool = mapPoolCache.get(cacheKey);
17
18
  if (pool !== undefined)
18
19
  return pool;
@@ -1,5 +1,5 @@
1
1
  import * as fs from 'fs';
2
- import { PMTiles, FetchSource, ResolvedValueCache, } from 'pmtiles';
2
+ import { PMTiles, FetchSource, SharedPromiseCache, } from 'pmtiles';
3
3
  import { GetObjectCommand, } from '@aws-sdk/client-s3';
4
4
  import { LRUCache } from 'lru-cache';
5
5
  import { getS3Client } from '../s3.js';
@@ -82,13 +82,15 @@ async function getPmtilesSource(uri, cache = noneCache()) {
82
82
  const val = await cache.get(uri);
83
83
  if (val !== undefined)
84
84
  return val; // hit
85
+ // Another request may have created the archive while cache.get awaited.
86
+ pmtiles = pmtilesCache.get(pmtilesUri);
85
87
  if (pmtiles === undefined) {
86
88
  const userAgent = getUserAgent();
87
89
  const headers = new Headers();
88
90
  if (userAgent)
89
91
  headers.set('User-Agent', userAgent);
90
92
  const fetchSource = new FetchSource(pmtilesUri, headers);
91
- pmtiles = new PMTiles(fetchSource, new ResolvedValueCache());
93
+ pmtiles = new PMTiles(fetchSource, new SharedPromiseCache());
92
94
  pmtilesCache.set(pmtilesUri, pmtiles);
93
95
  }
94
96
  }
@@ -97,19 +99,25 @@ async function getPmtilesSource(uri, cache = noneCache()) {
97
99
  const bucket = pmtilesUri.replace('s3://', '').split('/')[0];
98
100
  const key = pmtilesUri.replace(`s3://${bucket}/`, '');
99
101
  const s3Source = new S3Source(bucket, key);
100
- pmtiles = new PMTiles(s3Source, new ResolvedValueCache());
102
+ pmtiles = new PMTiles(s3Source, new SharedPromiseCache());
101
103
  pmtilesCache.set(pmtilesUri, pmtiles);
102
104
  }
103
105
  }
104
106
  else {
105
107
  if (pmtiles === undefined) {
106
108
  const fileSource = new FilesystemSource(pmtilesUri);
107
- pmtiles = new PMTiles(fileSource, new ResolvedValueCache());
109
+ pmtiles = new PMTiles(fileSource, new SharedPromiseCache());
108
110
  pmtilesCache.set(pmtilesUri, pmtiles);
109
111
  }
110
112
  }
111
113
  const [z, x, y] = uri.replace(`pmtiles://${pmtilesUri}/`, '').split('/');
112
- const tile = await pmtiles.getZxy(Number(z), Number(x), Number(y));
114
+ const tile = await pmtiles.getZxy(Number(z), Number(x), Number(y)).catch((err) => {
115
+ // SharedPromiseCache retains rejected metadata promises. Rebuild after a
116
+ // failure, without evicting a replacement created by a newer request.
117
+ if (pmtilesCache.get(pmtilesUri) === pmtiles)
118
+ pmtilesCache.delete(pmtilesUri);
119
+ throw err;
120
+ });
113
121
  if (!tile)
114
122
  return null;
115
123
  const buf = Buffer.from(tile.data);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.23.7",
4
+ "version": "1.23.8",
5
5
  "description": "Tiny map rendering server for MapLibre Style Spec",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",