-
Notifications
You must be signed in to change notification settings - Fork 438
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 multiple api calls on route change #2510
Fix multiple api calls on route change #2510
Conversation
…tliple-api-calls-on-route-change
…tliple-api-calls-on-route-change
c36fe6c
to
7a8e220
Compare
Thanks @artlowel! I tested the patch by opening the network tab of my browser dev tools and clearing it before navigating to another route. Before applying I would see two requests to I was +1 on this until I realized that it reliably breaks my login dropdown menu:
The console shows:
|
@alanorth I can reproduce your issue only when the backend is down. It makes sense that you can't log in when the backend is down. After it is back up, logging in works again for me. I did however discover a bug where the login dropdown goes blank if you enter the wrong account details. But I can reproduce that on both https://demo.dspace.org/ and on https://sandbox.dspace.org/, so it's not related to this PR. I created an issue for it: #2515 |
@artlowel I just tried again, and my backend is definitely up because I can browse everywhere in the repository, but my login dropdown is white. Shift refresh, nothing. See quick demo (use Chrome to view the video, GitHub mp4 is broken on Firefox): api-routes.mp4Another thing I noticed is that some browse pages actually make THREE calls to |
@artlowel if I revert the patch the white login dropdown issue goes away. Also note, in my video above, that I have not attempted login at all, so I'm not sure that bug is related to a failed login. |
@alanorth then that must mean that #2515 also happens for other errors, besides a failed login. Can you check your console when the blank dropdown issue happens. Is |
@artlowel yes, it is reliable. Right after applying the patch, Angular rebuilds, the page refreshes, and I get errors in the console. Three messages about missing links (one for authn, two for properties): |
@alanorth I'm able to reproduce your issue now. It happens only in dev mode. I'll take a look |
Just to quickly note that I get the same errors. Running in development mode with sandbox as API. I don't know if it's an issue but the I put in some |
…tliple-api-calls-on-route-change
It looks like CanActivate itself is also deprecated, which means that eventually we'll need to update all our guards. I think this is something that is best done all at once, e.g. in the context of the next angular upgrade |
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.
Just one question. Everything works as it should
…tliple-api-calls-on-route-change
@artlowel , great. I just wonder, because that number seems somewhat arbitrary, if it's possible to leave a comment to explain why it's 6 hours and not something else, or if there is something dependent on it being at least a specific value? |
Merging this as it has been tested by myself and @J4bbi, with our review feedback addressed. I think if we want to add a comment about the six hours you can add that later and we can merge it without testing all that. |
Backport failed for Please cherry-pick the changes locally. git fetch origin main
git worktree add -d .worktree/backport-2510-to-main origin/main
cd .worktree/backport-2510-to-main
git checkout -b backport-2510-to-main
ancref=$(git merge-base 2d733732f626bb3fb0a0e7a528334e5187fde542 67a6f58865b3b0da5da950adc10d21c49e83c043)
git cherry-pick -x $ancref..67a6f58865b3b0da5da950adc10d21c49e83c043 |
It doesn't have to be any specific value no. The original idea was that it should basically never expire because all the /api endpoint was used for was to retrieve the links to all other endpoints, and those only change if major new features are added to dspace. So 6 hours was chosen as just "a long time". With the introduction of the ServerCheckGuard, that this PR makes some tweaks to, that endpoint is used to check that the server is still running as well. So in practice those 6 hours will never be reached, because the timer will restart every time you switch routes. The reason I still rolled back the change though, is because I don't want to introduce issues where the validity expires while you're on a page and not doing anything. In theory, if everything else is properly designed to use dataservices and work with the cache that shouldn't be a problem, it would just cause /api to be re-requested automatically when that time is up. But I'd rather not risk introducing new edge cases that haven't been tested for |
@artlowel the automatic port to |
References
Description
The issue was caused by the fact that the guard made a new request to the api every time something subscribed to the result of its canActivateChild method. That happened more then once per route change
The solution was to use the cached /api response, and invalidate that cache on every NavigationStart event. That way, the first subscriber triggers the re-request, and all the others use the cached version.
Instructions for Reviewers
Open the network tab in the browser's dev tools, and check that there's one a single /api request every time you change the route
Also verify that if the backend becomes unavailable, that you're redirected to the 500 error page the next time you change the route
Checklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
yarn lint
yarn check-circ-deps
)package.json
), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.