-
Notifications
You must be signed in to change notification settings - Fork 0
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
Use cache_accesor for organization permissions related methods #178
base: master
Are you sure you want to change the base?
Conversation
Looks good! However, a long time ago I benchmarked the cache_accessor and I got that the whole metaprogramming thing was costlier than the chaced method if its code was fast enough. So I'd recommend benchmarking both versions in order to decide if it is actual an improvement or new performance issue. |
PS: I see that both methods are actually hitting the DB, so it makes sense to cache them when possible, although the net time it will take may be a little more - because ActiveRecord will cache
|
@flbulgarelli I've implemented your suggestion. Memoization of this methods may cause issues for uncontextualized users. When an user is instanced, both methods are called in order to define the current_context with the sole purpose of assigning a random avatar if it does not have one. |
Ok, the test actually passed 😛 but I suspect it's because they are run together and that changes something. If you run just the last test I've added it fails, and that makes sense. It's because of what I've explained just above. |
If we do end up merging this one despite that possible issue, let's remove the last test. |
PS: I agree with this:
|
This is not the first time I hit this problem in the last month. We should actually have some in-memory organization-sensitive cache store for a lot of things like that. Such cache would avoid a lot of usages queries - we could build an in-memory, organization-specific map for content-tree nodes. |
Yep, I agree with that last statement. In fact along with @julian-berbel we've proposed that same thing. He actually implemented some rudimentary version of that in the migration script but of course the actual implementation would be much more difficult. In this case I see it just a memoization pitfall though |
I've should have let it go like Frozen but I couldn't. I've renamed methods in auth to better reflect what they do. They don't actually retrieve organizations but they retrieve organizations names. You will see that I'm caching only the DB search. I'm a bit concerned that maybe this caching isn't truly speeding things as Rails does cache DB calls. I'm confident that, even Rails does that, it's cheaper this way 😄 |
Also, I was tempted to replace that |
This is minor, but as part of performance improvements, I think we should use
cache_accessor
more often.In particular,
student_granted_organizations
is used in core features like immersive redirections and profile completion and it's totally cacheable.Also, I was tempted to replace that Mumukit::Platform::Organization.find_by_name! for a Organization.where as Organization is being used in another places in this file, but I wanted to hear your opinion @flbulgarelli.