-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Rewrite subTypeInfo to use caching mechanism #14715
Conversation
(Standard links)
|
Test fails look related @eileenmcnaughton |
@seamuslee001 yeah this is more a discussion piece at the moment - I had some questions on it ^^ |
@eileenmcnaughton when you say it flatterns the key what do you mean? |
So the current function stores a static array $cache = ['permutation1' => x, 'permutation2' => y]; If we look at things like OptionGroup::values it saves a value for each option group which is like Cache->set('permutation1', x) This later feels better to me - except when you want to clear them all - which we would do here if editing contact subtypes |
IMHO, adding a new cache-group is probably the simplest way to get the desired effect. You'd probably want to:
There are alternatives, of course, e.g.
|
@totten so I feel like we'll quickly get a lot of containers then? Perhaps that is not a bad thing. We can declare them in extensions too it just feels kinda like a heavy lift |
"Bonus: The default cache doesn't specify withArray=>fast" @totten I thought we HAD made it so that we got fast cache mgemt by default? |
@eileenmcnaughton Yeah, there is a bit of boilerplate in declaring a cache. Something like this mitigates that. We can probably come up with a similar mitigation for flushCache() so that The most aggressive response to the boilerplate issue would be to move the cache mgmt out of |
I think that's true for caches that go through the |
hmm - I had thought we got to the point where Civi::cache()->get() WAS going through that adapter - we definitely don't want this (or the already merged groups one) to not be array backed. |
Discussion on chat https://chat.civicrm.org/civicrm/pl/9n5gbbesf3bsjn8dzw5q6bcgyw short version - this risks having a detrimental effect on performance for Redis/Memcache users without figuring out the fastArray stuff |
670f518
to
50a8e6f
Compare
Added 'has-test' because after stepping through the tests that failed when I made a mistake I can see there is pretty solid cover here |
50a8e6f
to
42a9f59
Compare
After reviewing the test fails I decided to rename the cache contactTypes since it needs to be cleared whenever the contact type cache is cleared (outside tests that should be rare) I also note that when adding or deleting a contactType we need to
I kinda wonder if Also I think we should add a pseudoconstant cache @seamuslee001 to move the cached vars in the Core_Pseudoconstant class into |
@seamuslee001 I think this is mergeable now |
CRM/UF/Page/ProfileEditor.php
Outdated
@@ -50,7 +50,7 @@ public static function registerProfileScripts() { | |||
'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), | |||
], | |||
'initialProfileList' => $ufGroups, | |||
'contactSubTypes' => CRM_Contact_BAO_ContactType::subTypes(), | |||
'contactTypes' => CRM_Contact_BAO_ContactType::subTypes(), |
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.
@eileenmcnaughton why the change of key here looks odd
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.
@seamuslee001 agree it looks wrong - changed it back
CRM_Core_BAO_Navigation::resetNavigation(); | ||
Civi::cache('contactTypes')->clear(); |
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.
why are you using clear()
here when we have consistently used flush()
which is an alias of clear
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.
because flush is actually deprecated!
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.
ok do we want consistance or non deprecated code paths :-P
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.
we get consistency when the others are migrated over
|
||
// reset the cache after adding | ||
self::subTypeInfo(NULL, FALSE, FALSE, TRUE); | ||
Civi::cache('contactTypes')->clear(); |
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.
same as L604
@@ -1442,6 +1442,7 @@ public static function flushCache() { | |||
Civi::cache('groups')->flush(); | |||
Civi::cache('navigation')->flush(); | |||
Civi::cache('customData')->flush(); | |||
Civi::cache('contactTypes')->clear(); |
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.
Same as on ContactType BAO L604
This seems to be getting a lot of cache misses on prod - presumably due to a lack of sub types so fixing to use 'modern caching';
42a9f59
to
81c4c14
Compare
ok i'm ok with this now and if Jenkins is then we can merge. I'm pretty confident we have good test coverage covering this |
@seamuslee001 thanks - working through this makes me feel like we probably also want a cache for 'pseudoconstants' - basically anything handled by CRM_Core_Pseudoconstant - It was a good exercise to work through |
Overview
Fix unnecessary DB lookups on sites with no sub types due to cache miss
Before
Cache being missed
After
Cache not being missed
Technical Details
So @totten @seamuslee001 I spotted this one getting a lot of setex in our redis logs & it also seems a good one for me to clarify the 'right' methodology. The issue here is that the change in this PR seems to work & fixes it but I'm no longer sure the best way to clear the cache - currently if you add a type it calls
This PR flattens the key so we would need to do multiple cache deletes to achieve the same - what is the right approach?
Comments