Skip to content

Commit

Permalink
Don't write to the cache in markResult if variables don't match
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 31, 2023
1 parent bb93818 commit 1bcaddb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,20 @@ export class QueryInfo {
variables: WatchQueryOptions["variables"]
) {
const { lastWrite } = this;
return !(
lastWrite &&
// If cache.evict has been called since the last time we wrote this
// data into the cache, there's a chance writing this result into
// the cache will repair what was evicted.
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
equal(variables, lastWrite.variables) &&
equal(result.data, lastWrite.result.data)
return (
// In case variables have changed and there is a race condition where the
// previous variables request finishes after the current variables
// request, skip the cache update.
equal(this.variables, variables) &&
!(
lastWrite &&
// If cache.evict has been called since the last time we wrote this
// data into the cache, there's a chance writing this result into
// the cache will repair what was evicted.
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
equal(variables, lastWrite.variables) &&
equal(result.data, lastWrite.result.data)
)
);
}

Expand Down

0 comments on commit 1bcaddb

Please sign in to comment.