OrchardCMS/Orchard

GetUser is called several times per pageload

MatteoPiovanelli-Laser opened this issue · 2 comments

public IUser GetUser(string username) {

This method is called a few times per pageload, because it's called by the provider for WorkContext.CurrentUser (when a User is authenticated).

We could cache the query inside this (per request, and my guts say only if a user is found) to save a few more queries being sent to the database.

A local cache should work fine. (in the scoped service)

I did more tests on this today with fresher eyes.

Looks like there is already a memorization happening per-workcontext, and the additional invocations I'm seeing are caused by filters and such having to generate a new WorkContext (e.g. OutputCacheFilter has to do this).
When a new WorkContext is instanced, its underlying providers (specifically the one for CurrentUser) are also reinstanced (that can make sense to me), so a local cache (on a simple level, a dictionary) gets reset.

That being the case I think I'd close this and leave things as they are.