Skip to content

Stabilize EDA filter serialization for improved caching#1625

Open
bobular wants to merge 1 commit intomainfrom
claude/cache-eda-computation-DsXvV
Open

Stabilize EDA filter serialization for improved caching#1625
bobular wants to merge 1 commit intomainfrom
claude/cache-eda-computation-DsXvV

Conversation

@bobular
Copy link
Copy Markdown
Member

@bobular bobular commented Feb 27, 2026

Summary

This PR improves cache hit rates by ensuring filters are serialized deterministically. Filter value arrays are now sorted consistently, and the filters array itself is sorted by entityId, variableId, and type. This stabilizes JSON representations sent to backend endpoints and react-query serialized keys on the client.

Key Changes

  • New utility function sortFilters(): Sorts value arrays within set-type filters (stringSet, numberSet, dateSet) and the filters array itself. Handles nested subFilters in multiFilter types while leaving range filters unchanged.
  • Integrated sorting in useAnalysisState hook: Wrapped the setFilters setter to automatically apply sortFilters() to all filter updates, ensuring consistency throughout the analysis state management.
  • Applied sorting in ComputeClient: Added sortComputeSpecFilters() helper to sort filters before sending compute requests to the backend, stabilizing the hash of configuration JSON for improved backend caching.
    • UPDATE the EDA compute service seems to do the sorting already
  • Sorted group selections in differential analysis plugins: Updated both differentialExpression.tsx and differentialabundance.tsx to sort group value options when selected and when swapping groups, ensuring deterministic ordering in the UI state.

Implementation Details

  • The sortFilters() function returns a new array without mutating the input, following functional programming principles.
  • Sorting uses locale-aware string comparison (localeCompare) for string fields and numeric comparison for number fields.
  • The swap groups operation now includes sorting to maintain consistency after the swap.
  • All changes are backward compatible and transparent to consumers of the filter APIs.

https://claude.ai/code/session_01RF8FbzBHq9ownjsqLrV81X

EDA computation results are cached on the backend based on a hash of
their configuration JSON.  Set-type filter values (stringSet, numberSet,
dateSet, multiFilter subFilters) were stored in user click-order, causing
cache misses when different users selected the same values in a different
order.  Similarly, react-query client-side cache keys were order-sensitive.

Changes:
- Add sortFilters() utility that sorts the value arrays inside each
  set-type filter and sorts the filters array by entityId/variableId/type
- Wrap setFilters in useAnalysisState to normalise on every update
  (covers client-side react-query keys and persisted analysis state)
- Sort filters at the ComputeClient boundary (postJobStatus and
  getComputedVariableMetadata) as a safety net for analyses loaded
  from storage that haven't been re-saved yet
- Sort groupA/groupB LabeledRange arrays by label in both
  differentialExpression and differentialabundance plugins, including
  the swap-groups handler

https://claude.ai/code/session_01RF8FbzBHq9ownjsqLrV81X
Copy link
Copy Markdown
Member Author

@bobular bobular left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Will test of course.

Wonder if a console warning should alert the developer to future filter types that aren't handled in the sort function (switch... default)

@bobular bobular changed the title Stabilize filter serialization for improved caching Stabilize EDA filter serialization for improved caching Mar 12, 2026
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