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

Theming, currentUser, and the assets service (deprecate per user theme) #1131

Closed
alexweissman opened this issue Dec 9, 2020 · 4 comments · Fixed by #1160
Closed

Theming, currentUser, and the assets service (deprecate per user theme) #1131

alexweissman opened this issue Dec 9, 2020 · 4 comments · Fixed by #1160
Assignees
Labels
architecture Related to the framework architecture assets Related to the assets feature
Milestone

Comments

@alexweissman
Copy link
Member

Our current implementation of theming allows the currentUser service to dynamically load a sprinkle based on the users.theme column in the database. Since theme sprinkles can potentially contain assets, the assets service is overridden to force the currentUser service to boot up on every request.

This created a potential performance issue in that the database had to be queried for every request - including requests for raw assets. To solve this, the current user object is now automatically cached on disk (or in redis) for a period of time (522f99e).

This caching is done in the Authenticator:: validateUserAccount method. However this does not account for any custom implementations outside of the Authenticator class. For example, I override the currentUser service to dynamically load a user subtype model depending on the value of a user type column. This causes the database to be hit via the currentUser service, which is forced to boot by the assets service.

I actually don't even use the theming feature, so one possibility would be to simply disable theming somehow so that assets doesn't need to boot currentUser. Or, I could have the ability to define my own custom Authenticator class that caches my subtype model along with the original user model. This is not possible at the moment because there are a few hard dependencies on the Authenticator class instead of depending on an interface.

My final option is to check the request path in my currentUser model and skip loading the subtype model if the request is for a raw asset. This seems rather kludgy though.

Does it really make sense to implement per-user themes on the sprinkle level at all? Also, we should remove the hard dependencies on Authenticator and replace with an interface.

@alexweissman alexweissman added architecture Related to the framework architecture assets Related to the assets feature labels Dec 9, 2020
@lcharette
Copy link
Member

I see many potential solutions :

  1. Get rid of per user theme (not actually used anywhere afaik in the default install). It could still be added back in a user sprinkle.
  2. Add more caching (for the user theme)
  3. Add a config to disable user theme check globally
  4. Find a better solution than currentUser service

@alexweissman
Copy link
Member Author

Maybe we can deprecate sprinkle-based theming, with a config setting to disable it in the meantime? I'm not really sure that there is any reason to conditionally load assets/templates/whatever based on the current user. I've found it more tractable to add logic within specific endpoints when I need the interface to vary substantially from user to user.

I guess there is an argument for using themes to implement access control to images, for example, but this can just as easily be done with a custom endpoint.

On top of this, we should use an AuthenticatorInterface so that one could swap in their own custom authenticator class (and do more caching if they want).

@lcharette
Copy link
Member

And considering the inevitable switch to a separate frontend system like vue or React in the future, per user theme on the server side will probably be obsolete anyway.

@lcharette lcharette added this to the 4.6.0 milestone Apr 27, 2021
@lcharette
Copy link
Member

I'll see if I can mark this feature as deprecated for 4.6, so we can completely remove it next version.

@lcharette lcharette self-assigned this Apr 27, 2021
@lcharette lcharette changed the title Theming, currentUser, and the assets service Theming, currentUser, and the assets service (deprecate per user theme) Apr 29, 2021
lcharette added a commit that referenced this issue Apr 30, 2021
@lcharette lcharette mentioned this issue May 1, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Related to the framework architecture assets Related to the assets feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants