-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
dev/core#1674: fix rebuilding of container on every request #16919
Conversation
(Standard links)
|
Since this PR does alter executable source code (and as you said yourself in the description "This fixes API4 functionality in CiviCRM Core"), I'm removing the NFC label. See these PR docs for more on the subject, and please let me know if they are unclear. |
@colemanw could you do PR review? |
@jaapjansma if this is a regression (as you indicate) it should go against the rc branch. Having said that it's probably better to wait for @colemanw to take a look at the best place to cache this. |
@colemanw can you look at this before the next rc is cut? |
I have submitted a new PR against the 5.23 branch, is that wou meant against the RC? |
I think this makes sense but I'd like to get input from @totten |
Ooooh. I was a bit confused at first because nothing in the previous code directly suggested that it would rebuild non-existent directories. But digging into public function isFresh($timestamp)
{
if (!is_dir($this->resource)) {
return false; // To wit: a non-existent directory will force a rebuild
} I'm giving this some |
Regarding when a directory is added/removed in an extension this would probably happen when someone updates an extension and a cache clear is a common action to do after updating extensions. And I believe that it does this automatically |
Conceptually, you want to: * (A) Keep the container cache when nothing has changed (regardless of whether that status-quo has an API4 subscriber folder). * (B) Update the cache if Civi/Api4/Event/Subscriber/*.php has been newly created * (C) Update the cache if Civi/Api4/Event/Subscriber/*.php has been newly removed To test this out, I hacked `Civi\Core\Container::loadContainer()` to emit a debug message to indicate if it is reusing the cache or updating. Then, I prepared two terminals for running alternate steps: * In terminal 1, go back and forth with adding/removing folders/files like `Civi/Api4/Event/Subscriber`. * In terminal 2, periodically run `cv ev 'echo "Hello\n";'` and note whether the cache is update. In this way, we can see if a developer action (adding a file) leads to an automatic update in the cache. I found that the previous commit fixed (A) and did (C), but it failed to update per (B). This commit should handle (A), (B), and (C).
Thanks @totten for doing this more in a symfony way! |
@totten I'm on the fence about master vs rc for this - I would lean rc but it's so close to release date - however, if it feels very safe to you I would go rc |
@jaapjansma Cheers :) Yeah, there's a little known setting
@eileenmcnaughton - I view it as moderately safe after running a few different use-cases. My initial gut would be |
@totten I think either is fine since it's not super recent - tests have passed - shall we merge? |
CRM/Api4/Services.php
Outdated
// about the directory's existence, which would make it redundant with the | ||
// newer "file_exists()" guard. However, the actual "catch()" seems broader, | ||
// and I don't see anything in DirectoryResource that throws the exception. | ||
// So... maybe it's not needed, or maybe there's some additional purpose. |
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.
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.
@colemanw Cool. I've cleaned up that bit and re-tested.
Overview
The civicrm container should be cached and build once. However if an extension is installed and enabled and it does not contain the directories
Civi/Api4/Event/Subscriber
andCivi/Api4/Service/Spec/Provider
the container is rebuild upon every request.This ia non-functional change.
Before
The civicrm container is rebuild upon every request.
After
The civicrm container is loaded from cache.
How to test
Comments
This fixes API4 functionality in CiviCRM Core. I will also provide a separate PR for the api4 extension. However I am also convinced that this should not be in core at all.
See also https://lab.civicrm.org/dev/core/-/issues/1674