Skip to content

perf(fs): probe tile extensions with File.Exists instead of directory glob (MAPCO-11364 P14) - #261

Open
shimoncohen wants to merge 3 commits into
logic-3-io-asyncfrom
logic-3-p14-fileclient-fexists
Open

perf(fs): probe tile extensions with File.Exists instead of directory glob (MAPCO-11364 P14)#261
shimoncohen wants to merge 3 commits into
logic-3-io-asyncfrom
logic-3-p14-fileclient-fexists

Conversation

@shimoncohen

@shimoncohen shimoncohen commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

P14 of MAPCO-11364 (LOGIC-3 I/O follow-up). Stacked on #257 (logic-3-io-async) — retarget to master after #257 merges.

Change

FileClient.GetTilePath (used by GetTile and TileExists) globbed the directory with EnumerateFiles(path, "{z}/{x}/{y}.*") on every call. Replaced with direct File.Exists probes of the supported extensions — jpeg then png.

  • File.Exists returns false for both a missing tile and a missing directory, so the DirectoryNotFoundException catch is no longer needed and is removed.
  • The probe set is sourced from Enum.GetValues<TileFormat>() — the TileFormat enum is the single source of truth, so a new format is covered automatically (no hardcoded array).

Cross-cutting: TileFormat enum reordered

TileFormat is reordered Jpeg, Png (was Png, Jpeg) so declaration order — which is now the probe order via Enum.GetValues — keeps jpeg first, matching the S3 client's historical probe order.

  • Verified no int-value coupling on TileFormat: no (int) casts, no default(TileFormat) reliance, no ordinal indexing. All 11 usages are explicit .Jpeg/.Png. The reorder is behavior-preserving.
  • Full MergerLogic suite (1117) and MergerService suite (23) both green after the reorder.

Follow-up

The extension string is still derived from format.ToString().ToLower() (here and in PathUtils), which only coincidentally equals the [EnumMember] value. Tracked as MAPCO-11369 (make the EnumMember value the source of truth for the extension).

Tests

  • GetTile / TileExists now mock Path.Combine + File.Exists via a shared SetupTilePathProbe helper (png setups omitted when jpeg is found, per strict mocks).
  • TileExistsReturnFalseWhenDirectoryDontExist removed — File.Exists never throws on a missing directory, so the scenario collapses into the normal "not found → false" case.
  • FileClient suite: 10 passed, 0 failed.

Scope

Only FileClient (+ the TileFormat reorder). Sibling 11364 items (P5r, P11, P10r, P15, P4) are separate PRs.

🤖 Generated with Claude Code

… glob (MAPCO-11364 P14)

FileClient.GetTilePath enumerated the directory with a `{z}/{x}/{y}.*` glob per
GetTile/TileExists. Replace with direct File.Exists probes of the known jpeg/png
extensions (jpeg first, matching the S3 client). File.Exists returns false for a
missing tile or missing directory, so the DirectoryNotFound catch is dropped.

Tests updated to mock Path.Combine/File.Exists; the now-unreachable
DirectoryNotFound test is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shimoncohen shimoncohen self-assigned this Aug 6, 2026
shimoncohen and others added 2 commits August 6, 2026 11:52
FileClient now iterates Enum.GetValues<TileFormat>() instead of a hardcoded
{Jpeg, Png} array, so new tile formats are covered automatically. The TileFormat
enum is reordered to Jpeg, Png so declaration order (= probe order) keeps jpeg
first, matching the S3 client's historical probe order.

No int-value coupling on TileFormat exists (no casts, no default(TileFormat)
reliance), so the reorder is behavior-preserving.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants