Skip to content

fix(hydra): deduplicate resource parameter discovery - #179

Open
J3m5 wants to merge 1 commit into
mainfrom
fix/cache-hydra-resource-parameters
Open

fix(hydra): deduplicate resource parameter discovery#179
J3m5 wants to merge 1 commit into
mainfrom
fix/cache-hydra-resource-parameters

Conversation

@J3m5

@J3m5J3m5 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • remove the unsupported itemsPerPage property passed to fetch
  • cache Hydra resource parameter discovery per Resource instance
  • deduplicate concurrent parameter requests
  • cache successful empty results
  • evict rejected requests from the cache to allow retries
  • document the cache lifetime

Context

Hydra resource parameters are discovered by requesting the collection endpoint
and reading its hydra:search mapping.

The parser previously passed itemsPerPage as a RequestInit property. This
property is not supported by fetch and was silently ignored. In addition,
concurrent calls to getParameters() or repeated calls returning no parameters
could trigger multiple identical collection requests.

The result is now stored in a WeakMap keyed by the Resource instance. This
keeps caches isolated between documentation parses and allows entries to be
garbage-collected with their resource.

Rejected requests are removed from the cache so that a later call can retry.

This change does not remove the initial Hydra discovery request or assume an
API Platform-specific pagination parameter. It prevents repeated discovery
requests in a generic way.

Related to #115.
Related to api-platform/admin#508.

Tests

Added dedicated coverage for:

  • successful caching and concurrent request deduplication
  • empty parameter results
  • retries after a failed request
  • cache isolation between resources sharing the same URL

The parser test retains integration coverage for wiring getParameters() and
the resulting fetch request.

Validation:

  • 30 tests passing
  • TypeScript typecheck
  • Oxlint
  • Prettier
  • git diff --check

@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🟢Lines72% (🎯 70%)306 / 425
🟢Statements71.96% (🎯 70%)308 / 428
🟢Functions70.76% (🎯 70%)46 / 65
🟢Branches60.8% (🎯 58%)242 / 398
File Coverage
FileStmtsBranchesFunctionsLinesUncovered Lines
Changed Files
src/hydra/fetchResource.ts100%80%100%100%
src/hydra/getParameters.ts95%80%100%94.73%39
src/hydra/parseHydraDocumentation.ts86.57%79.84%90.9%86.57%39, 69-71, 77, 85-87, 91-93, 121-127, 133, 140-142, 222, 236, 259, 282-289, 350, 361-366, 447
Generated in workflow #320 for commit 612b0ee by the Vitest Coverage Report Action

Sign up for freeto 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.

1 participant

@J3m5