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

🌵[spike] Fixed redundant member data loading for static assets #20031

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ronaldlangeveld
Copy link
Member

@ronaldlangeveld ronaldlangeveld commented Apr 17, 2024

ref CFR-21

  • Added known routes where we don't need this middleware from executing which is then bypassed from executing the memberSession middleware via a conditional middleware router.
  • Added testing to that will determine when the loadMemberSession is executed on a request. This should also prevent future implementations from breaking.

ref CFR-21

- Spike WIP
- Added testing to spy that will determine when the loadMemberSession
  is executed on a request.
- Added known routes where we don't need this middleware from executing.
- The method currently used is to reorganise the pattern in which the middleware loads, ensuring we only execute `loadMemberSession` where needed, after the the paths that don't require it.
@ronaldlangeveld ronaldlangeveld marked this pull request as ready for review April 17, 2024 12:53
@ronaldlangeveld ronaldlangeveld changed the title 🌵 Fixed redundant member data loading for static assets Fixed redundant member data loading for static assets Apr 17, 2024
const membersService = require('../../../server/services/members');

function conditionalMemberSessionMiddleware(req, res, next) {
const bypassMembersSession = [
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I'm not sure I'm too keen on this - I don't think it should be the responsibility of this middleware to know the specifics of defined routes (and this would likely turn into a maintenance burden)

Would be better to somehow inverse this - Let the route decide if it needs the member session?

Or could it be as simple as attempting to load the member session later in the request cycle (after the middleware processing the static assets has been executed)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I would be great to rubber duck a bit around this. ☺️

My initial idea was to pass in the member session middleware passed into routes, but after investigation, I realised there may be too many variables involved in the frontend app (it's not quite like the admin/content API with each route explicitly defined).
That lead me to do it at middleware level, since the member session is already passed in globally, it would be simpler to filter out the routes by the time they are already defined, in the middleware.

Either way, I think we have some decent testing on this PR, so we can play around and see what works best in terms of maintainability and best practices.

@ronaldlangeveld ronaldlangeveld changed the title Fixed redundant member data loading for static assets 🌵[spike] Fixed redundant member data loading for static assets May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants