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
#4445 - Cache UserSettings() lookup of org.couchdb.user #4988
#4445 - Cache UserSettings() lookup of org.couchdb.user #4988
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one. I think it's probably worth doing.
We don't a good idea of what to do if the userCtx doc changes. We have code in the Inbox controller that listens for this doc changing and prompts the user to refresh so they get the new permissions. Given this I think you can safely remove the Cache invalidation function. It's not particularly expensive (string concat) but it will be run on every doc change so might be worth saving...
@garethbowen That makes sense - I didn't know about the existing watch. Updated. |
5ef411c
to
3bcb496
Compare
@garethbowen Enough changes to tests that it'd be nice to have another review.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned a watch on the org.couchdb.user doc, but I am not actually able to find that specifically. Got a pointer for me to the code? I tested and I believe I can edit the doc of the current user, sync, and I am not prompted to reload.
Right at the bottom of the InboxCtrl there's a Changes watch that I think is supposed to do this - it may be broken though!
Some e2e tests write to org.couchdb.user object during the test, so I've changed the pattern they use for that. Now I set a default empty user-contact for all tests and tests edit the user-contact object. Feels a bit sloppy maybe? Alternative is to cache bust or something.
I like it. This helps move us away from changing too much during the test run which is great because currently changing stuff requires a browser reload which is slow and flakey. I want us to get to a point where all the users, docs, forms, etc are created before the e2e test browser is even started and then all the tests run in one go.
Added caching to UserDistrict just for prosperity but after updating all tests, I don't think this is used anywhere in the product. May be better to just remove it.
Yeah it looks like you're right! Delete it! Good spotting.
9245e9c
to
0c3194b
Compare
@kennsippell Did you get the prompt to show when the user settings doc changed? |
@garethbowen Yep. Only fires when you change roles. I was being too conservative with my changes to the document. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Description
The contact's tab fetches the org.couchdb.user document three times just to render. Although it isn't a particularly expensive operation, it is done frequently. Since this document has very low churn, it should be safe to cache it in UserSettings() in a similar style to Settings().
#4445 (Suggestion 8)
In this change, I'm also caching the userCtx cookie in Session. I'm assuming this is low-risk since the cookie is symantically immutable. I did not attempt to measure the impact. I'm doing this because this is another very hot codepath and the
ipCookie('userCtx')
function does the following:;
=
Impact
I timed how long the fetch for
org.couchdb.user
took while loading pages and while idle on my SM-G361H. An average range was between ~8-15ms when idle and ~80-130ms while the contacts page was loading. This is not a large savings by any means (3x savings for contacts page), but this is a frequent fetch across many user-actions and experiences.Navigating directly to
http://upstream:5988/muso/_design/medic/_rewrite/#/contacts
loads the org.couchdb.user 7 times (4 for any pageload + 3 for contacts page).Review checklist
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.