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

Optimize repeated apollo-cache-inmemory reads by caching partial query results. #3394

Merged
merged 97 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
2423c22
Disable auto-git-add behavior.
benjamn Apr 12, 2018
4c0aacf
Implement graphql-anywhere functionality with local module.
benjamn Apr 12, 2018
7876276
Move readStoreResolver from readFromStore.ts into graphql.ts.
benjamn Apr 12, 2018
ea76ac7
Rename src/graphql.ts to src/queryStore.ts.
benjamn Apr 12, 2018
fa2e1d3
Import FragmentMatcher from src/queryStore.ts.
benjamn Apr 12, 2018
e312a47
Move resultMapper function into queryStore.ts.
benjamn Apr 12, 2018
2017ff7
Eliminate unnecessary ExecOptions type.
benjamn Apr 12, 2018
55ad717
Rename queryStore to executeStoreQuery.
benjamn Apr 12, 2018
a537d24
Move ID_KEY declaration/export into executeStoreQuery.ts.
benjamn Apr 12, 2018
36a330f
Simplify and stop exporting Exec{Context,Info} types.
benjamn Apr 12, 2018
27d764e
Use ExecResult return type to avoid mutating context.hasMissingField.
benjamn Apr 12, 2018
3352240
Lock down ReadStoreContext properties to prevent errant mutations.
benjamn Apr 12, 2018
f102b3c
Remove unnecessary fragmentMap parameter from writeQueryToStore.
benjamn Apr 13, 2018
db22efd
Make all WriteContext members read-only.
benjamn Apr 13, 2018
4621f4c
Miscellaneous simplifications to store-writing functions.
benjamn Apr 13, 2018
8200d31
Get rid of NormalizedCacheFactory abstraction.
benjamn Apr 13, 2018
241ea87
Return early if shouldInclude(selection, variables) returns false.
benjamn Apr 13, 2018
b778044
Reimplement writeQueryToStore in terms of writeResultToStore.
benjamn Apr 13, 2018
e449625
Don't wait to call mergeWithGenerated until end of writeFieldToStore.
benjamn Apr 13, 2018
2f13741
Stop needlessly creating new NormalizedCache objects.
benjamn Apr 24, 2018
8327aac
Introduce OptimisticObjectCache to track data usage and invalidation.
benjamn Apr 14, 2018
01261fa
Enable OptimisticObjectCache as the default NormalizedCache.
benjamn Apr 14, 2018
36b3226
Declare defaultFragmentMatcher function once in exportStoreQuery.ts.
benjamn Apr 14, 2018
5ccd33c
Cache outermost executeStoreQuery results.
benjamn Apr 14, 2018
4225046
Apply optimistic caching to executeSelectionSet, too.
benjamn Apr 24, 2018
dfe7c61
Apply optimistic caching to executeField, too.
benjamn Apr 24, 2018
3b7c330
Give wrapped cached functions names for easier debugging.
benjamn Apr 25, 2018
a8e9127
Lift all returnPartialData logic into diffQueryAgainstStore.
benjamn Apr 25, 2018
5b5c6bf
Tolerate tolerable missing fields.
benjamn Apr 25, 2018
b2ea041
Fully remove returnPartialData property from ReadStoreContext.
benjamn Apr 25, 2018
106ac99
Lift all previousResult logic out of executeStoreQuery.
benjamn Apr 25, 2018
36182fd
Revert "Apply optimistic caching to executeField, too."
benjamn Apr 26, 2018
05e13f5
Rename OptimisticObjectCache to DepTrackingCache.
benjamn May 2, 2018
7ac6023
Add a brief CHANGELOG entry to pacify the Danger bot.
benjamn May 3, 2018
479c5d6
Completely remove unnecessary ID_KEY Symbol.
benjamn Jun 5, 2018
db55d27
Bump apollo-cache-inmemory npm version to 1.3.0-beta.0.
benjamn Jun 12, 2018
dcef720
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Jun 15, 2018
1cefd61
Bump apollo-cache-inmemory npm version to 1.3.0-beta.1.
benjamn Jun 15, 2018
047e976
Abandon merge if source === target.
benjamn Jun 15, 2018
da6e7b7
Bump apollo-cache-inmemory npm version to 1.3.0-beta.2.
benjamn Jun 15, 2018
b3242f2
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Jun 20, 2018
e1e1360
Tolerate frozen objects when merging properties in executeStoreQuery.
benjamn Jun 20, 2018
7578cec
Bump apollo-cache-inmemory npm version to 1.3.0-beta.3.
benjamn Jun 20, 2018
847411a
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Jul 5, 2018
8721375
Update optimism dependency of apollo-cache-inmemory to version 0.6.5.
benjamn Jul 5, 2018
e00f0b4
Bump apollo-cache-inmemory npm version to 1.3.0-beta.4.
benjamn Jul 5, 2018
d981e56
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Jul 18, 2018
a07b33d
Fix bogus OptimisticWrapperFunction import path in executeStoreQuery.…
benjamn Jul 17, 2018
b00a3e1
Convert __tests__/roundtrip.ts from CRLF to LF line endings.
benjamn Jul 17, 2018
3909ab6
Verify DepTrackingCache caching behavior in every roundtrip.ts test.
benjamn Jul 17, 2018
33d8362
Bump apollo-cache-inmemory npm version to 1.3.0-beta.5.
benjamn Jul 18, 2018
f29970a
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Jul 27, 2018
74e0b29
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Jul 27, 2018
00347ca
Make optimistic depend function a private member of DepTrackingCache.
benjamn Jul 27, 2018
e38a3eb
Convert src/types.ts from CRLF to LF line endings.
benjamn Jul 27, 2018
0eca85b
Merge executeStoreQuery.ts into readFromStore.ts.
benjamn Jul 27, 2018
4481349
Introduce StoreReader class for reading and diffing.
benjamn Jul 27, 2018
5c02c6c
Move cached executeStoreQuery function into StoreReader class.
benjamn Jul 27, 2018
09cbca7
Move execute{SelectionSet,Field,SubSelectedArray} into StoreReader cl…
benjamn Jul 27, 2018
1acbef6
Inline defaultFragmentMatcher function.
benjamn Jul 27, 2018
7b7ba9a
Bump apollo-cache-inmemory npm version to 1.3.0-beta.6.
benjamn Jul 27, 2018
3d8f8a5
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Aug 7, 2018
a3cc100
Make apollo-client depend on apollo-cache-inmemory@1.3.0-beta.6.
benjamn Aug 7, 2018
8d3770a
Make apollo-boost depend on apollo-cache-inmemory@1.3.0-beta.6.
benjamn Aug 7, 2018
5e0fdda
Avoid broadcasting watches when nothing has changed.
benjamn Aug 7, 2018
d962de4
Bump apollo-cache-inmemory npm version to 1.3.0-beta.7.
benjamn Aug 7, 2018
2debf6a
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Sep 11, 2018
274a730
Disable nonsensical tslint prepare step.
benjamn Sep 11, 2018
fcbf844
Bump apollo-cache-inmemory npm version to 1.3.0-beta.8.
benjamn Sep 11, 2018
05a13ee
Replace file:... versions in apollo-cache-inmemory/package.json.
benjamn Sep 11, 2018
3cf8e16
Bump apollo-cache-inmemory npm version to 1.3.0-beta.9.
benjamn Sep 11, 2018
3a0365d
Run `npm install` in subpackages instead of just `prepare`.
benjamn Sep 12, 2018
c148dcd
Revert "Avoid broadcasting watches when nothing has changed."
benjamn Sep 12, 2018
12d5db6
Bump apollo-cache-inmemory npm version to 1.3.0-beta.10.
benjamn Sep 12, 2018
c03924c
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Sep 14, 2018
b63eed0
Avoid broadcasting watches when nothing has changed, again.
benjamn Sep 14, 2018
4577534
Bump apollo-cache-inmemory npm version to 1.3.0-beta.11.
benjamn Sep 14, 2018
a388457
Convert apollo-cache-inmemory/CHANGELOG.md from CRLF to LF line endings.
benjamn Sep 14, 2018
ce4ce65
Note PR #3394 in CHANGELOG.md.
benjamn Sep 14, 2018
84fad50
Dirty maybeBroadcastWatch after any optimistic broadcast.
benjamn Sep 14, 2018
ee45dec
Bump apollo-cache-inmemory npm version to 1.3.0-beta.13.
benjamn Sep 14, 2018
6aa0d02
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Sep 20, 2018
0eea6f7
Move writeToStore.ts functions into a StoreWriter class.
benjamn Sep 14, 2018
c453e75
Use simple string as cache key for DepTrackingCache#depend.
benjamn Sep 17, 2018
45c4169
Reduce WeakMap usage by not using optimism defaultMakeCacheKey.
benjamn Sep 20, 2018
994cc67
Avoid WeakMap for InMemoryCache#transformDocumentCache.
benjamn Sep 20, 2018
8be655f
Bump apollo-cache-inmemory npm version to 1.3.0-beta.14.
benjamn Sep 20, 2018
ff66a02
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Sep 26, 2018
2170266
Add generic KeyType parameter to CacheKeyNode class.
benjamn Sep 25, 2018
acd2a67
Stop using InMemoryCache#transformDocument internally.
benjamn Sep 26, 2018
4a44a41
Allow structurally identical (sub)queries to share the same cache keys.
benjamn Sep 26, 2018
dcb8603
Be much more careful about calling cache.set in mergeWithGenerated.
benjamn Sep 27, 2018
6809e3d
Call store.set in writeFieldToStore only if new field value differs.
benjamn Sep 27, 2018
35cecb1
Bump apollo-cache-inmemory npm version to 1.3.0-beta.15.
benjamn Sep 27, 2018
ac82fdb
Merge branch 'master' into benjamn/cache-result-objects-with-optimism
benjamn Sep 28, 2018
8609fb6
Revert a few changes I made for my own convenience in PR #3394.
benjamn Sep 28, 2018
03a1236
Update apollo-cache-inmemory/package-lock.json.
benjamn Sep 28, 2018
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
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"license": "MIT",
"scripts": {
"postinstall": "lerna run prepare",
"postinstall": "lerna exec npm install",
Copy link
Member Author

@benjamn benjamn Sep 12, 2018

Choose a reason for hiding this comment

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

@hwillson This did fix my tests (which were previously failing because jest could not resolve the optimism dependency of apollo-cache-inmemory). Perhaps we should consider cherry-picking this change onto master, until this PR is merged?

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, on second thought, the Netlify deploy now seems to be failing when this command runs npm install in packages/apollo-boost, so I guess npm install has some drawbacks.

Copy link
Member

Choose a reason for hiding this comment

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

Sure thing @benjamn - a lot of the scripts can be streamlined further for sure. Right now prepare is also doing a first time build in child packages; do you think we should preserve that? If so we could maybe consider keeping this as lerna run prepare and instead modify the prepare script in each child package to be npm install && npm run build (we can drop the linting if we want, keeping it as optional).

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I just posted before seeing your second message. There's a combination of steps lurking here that should iron this all out for the better. I'll take a look as well. Thanks!

"diff": "check-if-folder-contents-changed-in-git-commit-range",
"build": "lerna run build",
"test": "jest --verbose",
Expand Down Expand Up @@ -71,12 +71,10 @@
},
"lint-staged": {
"*.ts*": [
"prettier --ignore-path \"./config/prettierignore\" --trailing-comma all --single-quote --write",
"git add"
"prettier --ignore-path \"./config/prettierignore\" --trailing-comma all --single-quote --write"
],
"*.js*": [
"prettier --ignore-path \"./config/prettierignore\" --trailing-comma all --single-quote --write",
"git add"
"prettier --ignore-path \"./config/prettierignore\" --trailing-comma all --single-quote --write"
]
},
"pre-commit": "lint-staged",
Expand Down
4 changes: 4 additions & 0 deletions packages/apollo-cache-inmemory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ the top level [`CHANGELOG.md`](https://github.com/apollographql/apollo-client/bl

- Not documented

### vNEXT
- Optimize repeated `apollo-cache-inmemory` reads by caching partial query results
[#3394](https://github.com/apollographql/apollo-client/pull/3394)

### 1.2.0

- Various optimizations for cache read performance
Expand Down
Loading