-
Notifications
You must be signed in to change notification settings - Fork 432
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
fix: prevent excessive requests to access endpoint #7597
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Oct 9, 2024 10:03 AM (UTC) ✅ All Tests Passed -- expand for details
|
⚡️ Editor Performance ReportUpdated Wed, 09 Oct 2024 10:14:49 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
Hey @rexxars. I've been reading through the changes, and the premise seems good to me. I could do with spending a bit more time to give a definitive 👍/👎. You mentioned you want to add some tests and that you opened this PR for an early look. Are you hoping to get this change merged by tomorrow? |
Might be a bit hopeful, I don't think realistically I/we will have much time for it this week :/ |
Okay, thanks for confirming. I will come back to it, as I'm likely to run out of time before tomorrow. |
ce02aa3
to
791cd61
Compare
Rendering the banner also triggers requests to APIs and calls other hooks. This is potentially expensive. The contents of the banner is never shown if the user has the right access to the document, and thus it is more efficient to do this check outside of the banner, before mounting it. Additionally, the name isn't quite right; it doesn't really _check_ for permissions, it just shows an error if told that it doesn't have the correct permissions. I've therefore chosen to rename it to `InsufficientPermissionsBanner` as I find that more precise.
791cd61
to
f7cfc6f
Compare
subscriptionRef.current = null | ||
} | ||
} | ||
}, [grantsStore, document, permission]) |
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.
This is one potential difference I can see between the createHookFromObservableFactory
implementation and your implementation: the former uses useUnique
, which in turn uses lodash.isEqual
to compare the args. You instead have added an effect with object dependencies that will behave differently.
Looks like you may have mitigated this by using disctinctUntilChanged
with lodash.isEqual
in the permissions$
observable—and there doesn't seem to be any issues—but thought I'd mention it in case.
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.
Conducted some testing and carefully compared to the previous implementation. It seems sound to me. Happy to re-review after tests added 👍.
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.
This looks solid to me. I've read through carefully and also tested quite a bit manually, and have not seen any issues. Thanks for not only fixing the issue at hand, but also for cleaning up and improving the code along the way! <3
Description
This one needs a proper read-through, I am not super confident with these changes - especially the last commit. There might be a lot easier ways to solve the problem outlined in the title here, but let me explain:
When researching why there were constant requests being fired to the
/access
API, I saw that it was due to a hook being run inside of the<PermissionCheckBanner />
. Upon further inspection, I saw that this component remounts (unmounts and mounts) constantly while edits are going on, due to the continuous evaluation of permissions as the document changes. When this happens, theisPermissionsLoading
state gets set totrue
, which triggers the banner to unmount. Once it's calculated if it should be allowed/disallowed, it re-mounts. My hunch is that this is not only causing the additional requests that we want to get rid of, but potentially also affects performance negatively.While reading the code of the
useDocumentValuePermissions
and the underlyingcreateHookFromObservableFactory
and friends, it seems like the intention is to keep the old state while recalculating - but because thedocument
being passed as an argument is recreated on any edit, the observable factory gets called again and the state resets. In my mind it would be better (for the permission check in particular) to assume that the grants don't change that quickly, and keep the old cached value around. I refactored the code to do this, but the code is a lot simpler/more naive thancreateHookFromObservableFactory
+useObservable
, so I'd be happy to have some more eyes on this and see if there are edge cases it wouldn't account for.Note
While writing this, I realized that we should probably throw away that cached value on document ID change.
Running the new eFPS suite, the eFPS looks about the same, while blocking time seems lower - lets see what another run says once I open the PR.
Aside from the above, I also refactored some code a bit - using observable requests for cancellation, minimizing state updates with predefined constants and preferring to "return early" from functions for less indentation (easier to read in my book).
What to review
I'd do commit-by-commit - most of the changes should be fairly straightforward, except the last two. In particular, the last change needs a very thorough read-through.
Testing
I want to add some tests for
useDocumentValuePermissions
, but figured I would open this up for an early look since it needs a proper read-through.Notes for release