Skip to content

Commit a3f49c2

Browse files
authored
fix: use the configuration version not time to reset cache (#3553)
### Motivation Loading a huge amount of tiffs to compile a configuration takes a long time in some cases 30+ minutes, when recompiling these configs as part of pull requests parts of the config can be cached so every individual tiff file does not need to be loaded. We current store that cache for a month and reset it on the first of the month, there is nothing stopping us storing that cache for longer as the first pull requests of the month take a long time to process as they are starting from a cold cache. ### Modifications Move the cache to only reset if a configuration change has been detected. ### Verification Unit tests/run locally
1 parent 4778a53 commit a3f49c2

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

packages/config-loader/src/json/imagery.config.cache.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { promisify } from 'node:util';
22
import { gzip } from 'node:zlib';
33

4-
import { sha256base58 } from '@basemaps/config';
4+
import { ConfigImageryVersion, sha256base58 } from '@basemaps/config';
55
import { fsa, LogType } from '@basemaps/shared';
66
import { FileInfo } from '@chunkd/fs';
77

88
import { ConfigImageryTiff } from './tiff.config.js';
99

10-
export const ConfigCacheVersion = `V1`; // TODO this could just be the config packageJson ?
10+
export const ConfigCacheVersion = `V1.` + ConfigImageryVersion; // TODO this could just be the config packageJson ?
1111

1212
const gzipPromise = promisify(gzip);
1313

@@ -17,7 +17,7 @@ const gzipPromise = promisify(gzip);
1717
* @example
1818
* ```
1919
* YYYY-MM/proto_hostname/hashKey.json.gz
20-
* 2034-04/s3_linz-imagery/Ci4chK59behxsGZq6TaUde5DoVb7jTxhyaZ44j4wBnCb.json.gz
20+
* 2034-04/s3/linz-imagery/Ci4chK59behxsGZq6TaUde5DoVb7jTxhyaZ44j4wBnCb.json.gz
2121
* ```
2222
*
2323
* @param sourceFiles
@@ -26,13 +26,17 @@ const gzipPromise = promisify(gzip);
2626
* @returns a unique config location
2727
*/
2828
function getCacheKey(sourceFiles: FileInfo[], cacheLocation: URL): URL {
29+
// All source hosts used for the config
30+
const sourceHosts = new Set(sourceFiles.map((m) => m.url.hostname));
31+
const hostNames = [...sourceHosts.values()];
32+
hostNames.sort();
33+
2934
const configKey =
3035
ConfigCacheVersion + sourceFiles.map((m) => `${m.url.href}::${m.size}::${m.lastModified}`).join('\n');
31-
// create a config hash based on the YYYY-MM/proto_hostname/hashKey.json.gz
3236

33-
const datePart = new Date().toISOString().slice(0, 7);
37+
// create a config hash based on the /proto/hostname/hashKey.json.gz
3438
const protoPart = cacheLocation.protocol.replace(':', ''); // convert file: into file
35-
const configKeyHash = [datePart, `${protoPart}_${sha256base58(configKey)}_.json.gz`].join('/');
39+
const configKeyHash = [protoPart, hostNames.join('__'), `${sha256base58(configKey)}_.json.gz`].join('/');
3640
return new URL(configKeyHash, cacheLocation);
3741
}
3842

packages/config/src/config/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { ConfigId } from '../index.js';
3+
import { ConfigId } from '../base.config.js';
44

55
/**
66
* Ensure a ID is prefixed with one of the configuration objects

packages/config/src/config/imagery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { z } from 'zod';
33

44
import { ConfigBase } from './base.js';
55

6+
export const ConfigImageryVersion = 2;
7+
68
/**
79
* Taken from tiff's SampleFormat
810
*
@@ -212,7 +214,7 @@ export const ConfigImageryV1Parser = ConfigImageryBase.extend({
212214
* Version two of imagery configuration adds more information about the bands found inside the imagery
213215
*/
214216
export const ConfigImageryV2Parser = ConfigImageryBase.extend({
215-
v: z.literal(2),
217+
v: z.literal(ConfigImageryVersion),
216218

217219
/** Human friendly title for the imagery */
218220
title: z.string(),

packages/config/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
ConfigImagery,
1515
ConfigImageryOverview,
1616
ConfigImageryV1,
17+
ConfigImageryVersion,
1718
ImageryBandDataType,
1819
ImageryBandType,
1920
ImageryDataType,

0 commit comments

Comments
 (0)