-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: resolve tile keys in the tiles-deletion strategy (MAPCO-11269) #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
914f8a4
feat: implement tile key generation for S3, FS, and Redis storage pro…
almog8k 527aef3
refactor: simplify documentation for tile-key format resolution
almog8k a1d1ff7
refactor: move tile-key resolution into utils (MAPCO-11269)
almog8k 86f6b06
refactor: rename deleteAllTiles to deleteTiles for clarity
almog8k de36734
refactor: rename variable keysForRange to toKeys for clarity in tile …
almog8k 70cd0da
refactor: restructure tile key generation to use a unified generateRa…
almog8k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| export { getChunk } from './chunk'; | ||
| export { assertCanDeleteFromFolder } from './fs'; | ||
| export { buildPollingPairs } from './pairBuilder'; | ||
| export { isPathWithinAllowedSubPaths, normalizeFolderPath, resolveAbsolutePath } from './path'; | ||
| export { | ||
| generateRangeKeys, | ||
| generateRedisTileKeys, | ||
| generateTilePaths, | ||
| isPathWithinAllowedSubPaths, | ||
| normalizeFolderPath, | ||
| resolveAbsolutePath, | ||
| } from './path'; | ||
| export { resolveTileKeyGenerator } from './tileKeys'; | ||
| export { validateSchema } from './validationHelper'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { StorageProvider, type TileRange, type TilesDeletionParams } from '@map-colonies/raster-shared'; | ||
| import { generateRedisTileKeys, generateTilePaths } from './path'; | ||
|
|
||
| /** | ||
| * Picks the tile-key format for a deletion request. Switching on the discriminant (rather than | ||
| * indexing a `Record<StorageProvider, …>`) is what narrows `params` per provider without a cast. | ||
| */ | ||
| export function resolveTileKeyGenerator(params: TilesDeletionParams): (range: TileRange) => Generator<string> { | ||
| switch (params.storageProvider) { | ||
| case StorageProvider.S3: | ||
| case StorageProvider.FS: | ||
| return (range) => generateTilePaths(range, params.tilesRelativePath, params.fileExtension); | ||
| case StorageProvider.REDIS: | ||
| return (range) => generateRedisTileKeys(range, params.prefix); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { faker } from '@faker-js/faker'; | ||
| import type { FsTilesDeletionParams, RedisTilesDeletionParams, S3TilesDeletionParams, TileRange } from '@map-colonies/raster-shared'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { resolveTileKeyGenerator } from '@src/cleaner/utils/tileKeys'; | ||
|
|
||
| const RANGE: TileRange = { zoom: 3, minX: 1, maxX: 2, minY: 5, maxY: 6 }; | ||
|
|
||
| /** | ||
| * Pins the key shape per storage provider. S3 and FS must stay byte-identical — the strategy | ||
| * relies on them sharing one key family — while Redis uses mapproxy's flat key format. | ||
| */ | ||
| describe('resolveTileKeyGenerator', () => { | ||
| const relativePath = `${faker.string.uuid()}/${faker.string.uuid()}`; | ||
|
|
||
| describe('S3', () => { | ||
| it('should yield a path per tile, ordered x-major then y', () => { | ||
| const params: S3TilesDeletionParams = { | ||
| storageProvider: 'S3', | ||
| bucket: 'b', | ||
| tilesRelativePath: relativePath, | ||
| fileExtension: 'png', | ||
| ranges: [RANGE], | ||
| }; | ||
|
|
||
| expect([...resolveTileKeyGenerator(params)(RANGE)]).toEqual([ | ||
| `${relativePath}/3/1/5.png`, | ||
| `${relativePath}/3/1/6.png`, | ||
| `${relativePath}/3/2/5.png`, | ||
| `${relativePath}/3/2/6.png`, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should use the requested file extension', () => { | ||
| const range: TileRange = { zoom: 0, minX: 0, maxX: 0, minY: 0, maxY: 0 }; | ||
| const params: S3TilesDeletionParams = { | ||
| storageProvider: 'S3', | ||
| bucket: 'b', | ||
| tilesRelativePath: relativePath, | ||
| fileExtension: 'jpeg', | ||
| ranges: [range], | ||
| }; | ||
|
|
||
| expect([...resolveTileKeyGenerator(params)(range)]).toEqual([`${relativePath}/0/0/0.jpeg`]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('FS', () => { | ||
| it('should yield the same path shape as S3', () => { | ||
| const fsParams: FsTilesDeletionParams = { | ||
| storageProvider: 'FS', | ||
| subPath: 'artifacts/tiles', | ||
| tilesRelativePath: relativePath, | ||
| fileExtension: 'jpeg', | ||
| ranges: [RANGE], | ||
| }; | ||
| const s3Params: S3TilesDeletionParams = { | ||
| storageProvider: 'S3', | ||
| bucket: 'b', | ||
| tilesRelativePath: relativePath, | ||
| fileExtension: 'jpeg', | ||
| ranges: [RANGE], | ||
| }; | ||
|
|
||
| expect([...resolveTileKeyGenerator(fsParams)(RANGE)]).toEqual([...resolveTileKeyGenerator(s3Params)(RANGE)]); | ||
| }); | ||
|
|
||
| it('should offset x and y when the range does not start at zero', () => { | ||
| const range: TileRange = { zoom: 7, minX: 3, maxX: 4, minY: 8, maxY: 9 }; | ||
| const params: FsTilesDeletionParams = { | ||
| storageProvider: 'FS', | ||
| subPath: 'artifacts/tiles', | ||
| tilesRelativePath: relativePath, | ||
| fileExtension: 'png', | ||
| ranges: [range], | ||
| }; | ||
|
|
||
| expect([...resolveTileKeyGenerator(params)(range)]).toEqual([ | ||
| `${relativePath}/7/3/8.png`, | ||
| `${relativePath}/7/3/9.png`, | ||
| `${relativePath}/7/4/8.png`, | ||
| `${relativePath}/7/4/9.png`, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('REDIS', () => { | ||
| it('should yield flat prefixed keys rather than paths', () => { | ||
| const prefix = 'myLayer-redis_WorldCRS84'; | ||
| const params: RedisTilesDeletionParams = { | ||
| storageProvider: 'REDIS', | ||
| prefix, | ||
| ranges: [RANGE], | ||
| }; | ||
|
|
||
| expect([...resolveTileKeyGenerator(params)(RANGE)]).toEqual([`${prefix}-3-1-5`, `${prefix}-3-1-6`, `${prefix}-3-2-5`, `${prefix}-3-2-6`]); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.