Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop paying attention to previousResult in InMemoryCache. #5644

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/cache/inmemory/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,15 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
return maybeBroadcastWatch.call(this, c);
}, {
makeCacheKey(c: Cache.WatchOptions) {
if (c.previousResult) {
// If a previousResult was provided, assume the caller would prefer
// to compare the previous data to the new data to determine whether
// to broadcast, so we should disable caching by returning here, to
// give maybeBroadcastWatch a chance to do that comparison.
return;
}
Comment on lines -99 to -105
Copy link
Member Author

@benjamn benjamn Dec 2, 2019

Choose a reason for hiding this comment

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

These are the "comments I removed" that I was referring to above. ♻️


if (supportsResultCaching(cache.data)) {
// Return a cache key (thus enabling caching) only if we're currently
// using a data store that can track cache dependencies.
// Return a cache key (thus enabling result caching) only if we're
// currently using a data store that can track cache dependencies.
const store = c.optimistic ? cache.optimisticData : cache.data;
if (supportsResultCaching(store)) {
const { optimistic, rootId, variables } = c;
return cache.cacheKeyRoot.lookup(
c.query,
JSON.stringify(c.variables),
store,
JSON.stringify({ optimistic, rootId, variables }),
);
}
}
Expand All @@ -136,7 +131,6 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
query: options.query,
variables: options.variables,
rootId: options.rootId,
previousResult: options.previousResult,
config: this.config,
}) || null;
}
Expand All @@ -159,7 +153,6 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
query: options.query,
variables: options.variables,
returnPartialData: options.returnPartialData,
previousResult: options.previousResult,
config: this.config,
});
}
Expand Down Expand Up @@ -305,7 +298,6 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
this.diff({
query: c.query,
variables: c.variables,
previousResult: c.previousResult && c.previousResult(),
optimistic: c.optimistic,
}),
);
Expand Down
13 changes: 0 additions & 13 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
getMainDefinition,
getQueryDefinition,
} from '../../utilities/graphql/getFromAST';
import { isEqual } from '../../utilities/common/isEqual';
import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze';
import { mergeDeepArray } from '../../utilities/common/mergeDeep';
import { Cache } from '../core/types/Cache';
Expand Down Expand Up @@ -141,10 +140,6 @@ export class StoreReader {
*
* @param {Object} [variables] A map from the name of a variable to its value. These variables can
* be referenced by the query document.
*
* @param {any} previousResult The previous result returned by this function for the same query.
* If nothing in the store changed since that previous result then values from the previous result
* will be returned to preserve referential equality.
*/
public readQueryFromStore<QueryType>(
options: ReadQueryOptions,
Expand All @@ -160,14 +155,12 @@ export class StoreReader {
* identify if any data was missing from the store.
* @param {DocumentNode} query A parsed GraphQL query document
* @param {Store} store The Apollo Client store object
* @param {any} previousResult The previous result returned by this function for the same query
* @return {result: Object, complete: [boolean]}
*/
public diffQueryAgainstStore<T>({
store,
query,
variables,
previousResult,
returnPartialData = true,
rootId = 'ROOT_QUERY',
config,
Expand Down Expand Up @@ -205,12 +198,6 @@ export class StoreReader {
});
}

if (previousResult) {
if (isEqual(previousResult, execResult.result)) {
execResult.result = previousResult;
}
}

return {
result: execResult.result,
complete: !hasMissingFields,
Expand Down