Skip to content

Conversation

@ntucker
Copy link
Collaborator

@ntucker ntucker commented Mar 10, 2025

Motivation

Sometimes deletes should occur based on something only the server knows - thus cannot be handled with static schema Invalidate. For instance, if we're tracking price levels for an order book, we need to remove any levels that reach 0.

Solution

Support dynamic invalidation/deletes

Returning undefined from Entity.process
will cause the Entity to be invalidated.
This this allows us to invalidate dynamically; based on the particular response data.

class PriceLevel extends Entity {
  price = 0;
  amount = 0;

  pk() {
    return this.price;
  }

  static process(
    input: [number, number],
    parent: any,
    key: string | undefined,
  ): any {
    const [price, amount] = input;
    if (amount === 0) return undefined;
    return { price, amount };
  }
}

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2025

🦋 Changeset detected

Latest commit: c863973

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@data-client/endpoint Patch
@data-client/graphql Patch
@data-client/rest Patch
example-benchmark Patch
normalizr-github-example Patch
normalizr-redux-example Patch
normalizr-relationships Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2025

Size Change: +24 B (+0.03%)

Total Size: 76.8 kB

Filename Size Change
examples/test-bundlesize/dist/rdc.js 15.1 kB +23 B (+0.15%)
ℹ️ View Unchanged
Filename Size Change
examples/test-bundlesize/dist/App.js 3.41 kB +1 B (+0.03%)
examples/test-bundlesize/dist/polyfill.js 311 B 0 B
examples/test-bundlesize/dist/react.js 57.3 kB 0 B
examples/test-bundlesize/dist/webpack-runtime.js 726 B 0 B

compressed-size-action

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark

Details
Benchmark suite Current: c863973 Previous: 39f9f7b Ratio
normalizeLong 525 ops/sec (±0.26%) 521 ops/sec (±1.12%) 0.99
infer All 8842 ops/sec (±2.11%) 8146 ops/sec (±1.79%) 0.92
denormalizeLong 263 ops/sec (±3.17%) 258 ops/sec (±2.38%) 0.98
denormalizeLong donotcache 912 ops/sec (±0.28%) 843 ops/sec (±0.53%) 0.92
denormalizeShort donotcache 500x 1413 ops/sec (±0.06%) 1394 ops/sec (±0.32%) 0.99
denormalizeShort 500x 781 ops/sec (±2.02%) 774 ops/sec (±2.11%) 0.99
denormalizeShort 500x withCache 5527 ops/sec (±0.27%) 5520 ops/sec (±0.13%) 1.00
denormalizeLong with mixin Entity 259 ops/sec (±2.16%) 253 ops/sec (±1.97%) 0.98
denormalizeLong withCache 7511 ops/sec (±0.20%) 6130 ops/sec (±0.14%) 0.82
denormalizeLong All withCache 7421 ops/sec (±0.17%) 8668 ops/sec (±0.33%) 1.17
denormalizeLong Query-sorted withCache 7089 ops/sec (±0.69%) 8659 ops/sec (±0.54%) 1.22
denormalizeLongAndShort withEntityCacheOnly 1714 ops/sec (±1.21%) 1668 ops/sec (±0.16%) 0.97
getResponse 7734 ops/sec (±1.28%) 6489 ops/sec (±1.32%) 0.84
getResponse (null) 5121575 ops/sec (±0.46%) 4853744 ops/sec (±0.64%) 0.95
getResponse (clear cache) 261 ops/sec (±2.11%) 260 ops/sec (±1.99%) 1.00
getSmallResponse 2937 ops/sec (±0.25%) 2863 ops/sec (±0.60%) 0.97
getSmallInferredResponse 2077 ops/sec (±0.24%) 2101 ops/sec (±0.17%) 1.01
getResponse Query-sorted 7142 ops/sec (±0.89%) 6248 ops/sec (±0.90%) 0.87
getResponse Collection 6830 ops/sec (±1.13%) 6703 ops/sec (±1.14%) 0.98
get Collection 6310 ops/sec (±0.45%) 5989 ops/sec (±0.34%) 0.95
setLong 529 ops/sec (±0.28%) 527 ops/sec (±0.59%) 1.00
setLongWithMerge 233 ops/sec (±0.91%) 227 ops/sec (±0.44%) 0.97
setLongWithSimpleMerge 248 ops/sec (±0.28%) 246 ops/sec (±0.29%) 0.99
setSmallResponse 500x 915 ops/sec (±0.36%) 928 ops/sec (±0.37%) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@codecov
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.74%. Comparing base (d085b5e) to head (c863973).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3407   +/-   ##
=======================================
  Coverage   98.74%   98.74%           
=======================================
  Files         136      136           
  Lines        2391     2396    +5     
  Branches      489      490    +1     
=======================================
+ Hits         2361     2366    +5     
  Misses         16       16           
  Partials       14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ntucker ntucker force-pushed the conditional-delete branch from 03d5b95 to c863973 Compare March 10, 2025 11:41
@ntucker ntucker requested a review from notwillk March 10, 2025 11:43
@ntucker ntucker merged commit d84899d into master Mar 10, 2025
23 checks passed
@ntucker ntucker deleted the conditional-delete branch March 10, 2025 11:51
@github-actions github-actions bot mentioned this pull request Mar 10, 2025
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