Needs work
Project:
Drupal core
Version:
main
Component:
cache system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Nov 2018 at 13:24 UTC
Updated:
5 Feb 2026 at 09:13 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
volegerFirst iteration. Moved function into a class as the static method. Replaced calls in the
coredirectory. Removed include on the utility.inc file in therebuild.phpscript.Todo:
@deprecatedannotation with message for deprecateddrupal_rebuildfunction@trigger_errorfunction in deprecateddrupal_rebuildfunctionComment #3
andypostNot sure that related to cache - it is more like controller
Comment #4
volegerMaybe, so why not to convert the rebuild.php script to the controller and keep there all related functionality from script including drupal_rebuild function?
Is it possible?
Comment #5
goodboy commentedAdd deprecated annotation and trigger_error function
Comment #6
goodboy commentedComment #7
andypostBtw while you on it - Icm sure it needs to check core commands, probably there is similar command so they could reuse same codebase
Comment #8
andypostComment #9
mile23It seems like
drupal_flush_all_caches()is doing most of the heavy lifting here.It doesn't have a 'kill includes' issue, either.
How about we turn
drupal_flush_all_caches()anddrupal_rebuild()into a class. Maybe call itCacheRebuilder.It seems like the replacement for
drupal_flush_all_caches()would be concrete (rather than static), so we could inject services, but it just rebuilds the container so maybe not.Comment #10
andypostI see no way,
rebuild.phpwas introduced exactly for the case when core can't bootstrap #2097189: Add a rebuild scriptComment #12
volegerI like the idea #9 with the rebuilder class.
Moved the method, deprecated
drupal_flush_all_caches()and_drupal_flush_css_js()functions.Comment #13
volegerComment #14
goodboy commentedI see bins deleted in Rebuilder::rebuild()
But Rebuild::flushAllCaches() has bins clearing code already
And this last bin clearer code has unused $service_id key.
So, it seems bins in Rebuilder::rebuild() were cleared twice. If this is correct then need create non-public member function binsClear() to exclude similar code in both functions. If this is incorrect then need remove bins clear code from Rebuilder::rebuild() and remove unused $service_id key from Rebuild::flushAllCaches().
Comment #15
voleger#14 nice catch and sounds reasonable to move that into the protected method
Comment #16
berdirThat we are clearing them twice is AFAIK actually a long-standing bug and there is an issue about that, so I wouldn't bother to make a method for that.
this was prefixed with an underscore, so it was considered an internal/private function. should we add a public replacement for that, are there any direct calls to it? If not we could make it protected and just keep the old code here, it's a single line anyway.
Checking below, looks like there are actually are some calls to it. interesting..
Naming...
I like putting all this stuff into a Rebuilder class.
But the thing is that flushAllCaches() obviously does so much more than that (to the point that I'm not sure that this should be in the cache component, it merely uses that, maybe Site or Utility instead?). It really is the rebuild part in this whole thing.
What the current rebuild() method really does is a safe bootstrap and then rebuild.
What about:
::rebuild() (or rebuildAll()?) instead of flushAllCaches()
::safeBootstrapAndRebuild() or something like that for the current rebuild()?
I'm always torn between doing 1:1 conversions to methods and actually improving things.
I'm pretty sure that list of persistent caches is way outdated, URL alias for example isn't its own cache bin anymore and doesn't seem worth mentioning here. Honestly, I'd just drop that ist and just say that all registered cache bins are cleared?
The part below rebuild is also outdated, the only thing that still implements that hook is block.module and the only thing that it does is disable blocks that are in invalid regions.
On the other side, we could maybe mention new things that are happening that are more important, like invalidating twig caches, and that kernel rebuild/service container invalidation?
Comment #17
volegerRerrolled.
Addressed #16.1 and #16.2
Comment #18
andypostRe-roll + fix for
\Drupal\system\Controller\DbUpdateController::triggerBatch()Comment #19
volegerLooks good +1 for RTBC
Comment #20
volegerComment #21
volegerNW regarding #16
Comment #22
volegerAdded legacy test, addressed #16.3, and simplified the ::safeBootstrapAndRebuild to ::safeBootstrap.
Comment #24
volegerReroll against 9.0.x
Also, there was the usage of the deprecated
prepageLegacyRequestmethod, so it was replaced with appropriate replacement.Comment #26
volegerMissed updates in the deprecation messages.
Comment #27
volegerComment #29
volegerNew required replacement detected)
Comment #30
volegerComment #31
volegerReroll.
Took into account changes from #3119373: Configuration synchronisation that both enables & configures a module fails and drupal_flush_all_caches()
The 9.1.x branch is opened, so reviews are welcome.
Comment #32
volegerFixed reroll issue
Comment #35
swatichouhan012 commentedRemove ununsed use statements from patch and coding fixes.
Comment #36
volegerAccidentally removed the body of the method. Restoring.
Comment #37
daffie commentedPatch no longer applies. Needs a reroll.
Comment #38
kishor_kolekar commentedComment #39
kishor_kolekar commentedRe-roll patch #36.
please review
Comment #41
mrinalini9 commentedFixing test case failure issues in #39, please review.
Comment #43
mrinalini9 commentedComment #44
mrinalini9 commentedFixed test case failure in #41, please review.
Comment #45
voleger+++ b/core/tests/Drupal/KernelTests/Core/DrupalKernel/RebuildLegacyTest.php
@@ -15,7 +15,7 @@
- protected function setUp() {
+ protected function setUp(): void
Missed
{in method definitionprotected function setUp(): void {Comment #46
deepak goyal commentedComment #47
deepak goyal commentedHi @voleger
Updated patch please take a look.
Comment #48
deepak goyal commentedComment #49
voleger+1 for RTBC. But still needs additional review, as I worked on the patches
Comment #50
andypostThe function needs be kept, NW for that
This function is used in contrib http://grep.xnddx.ru/search?text=_drupal_flush_css_js
SO should be deprecated to not break it
Comment #51
volegerBut it's an internal function. It has not to be used by definition. https://www.drupal.org/core/d8-bc-policy#underscore
Comment #52
kostyashupenkoComment #53
volegerAddressed #50
Comment #54
andypost@voleger Thank you, it looks mostly ready, just few places needs some work
There's no such classloaders in 9.x https://www.drupal.org/node/3116384
Looks we should
\Composer\Autoload\ClassLoaderas\Drupal\Core\DrupalKernel::__construct()definesboth todo needs issues and links
no reason for the variable as it used only once and redefined later
not sure
REQUEST_TIMEshould be used in new codeComment #55
volegerThanks for the review @andypost
Addressed #54:
1. Done. Used the same definitions from DrupalKernel.
2. Filled #3160185: [META] Improve Cache rebuild process. Added the link for the todo items.
3. Done
4. Done
Comment #56
voleger#55 is ready for another round of the review
Comment #57
volegerUpdated CR, IS and title to reflect actual scope of the task.
Comment #58
andypostIt still needs to update summary, and then it looks ready for commiter's eyes
Comment #59
volegerFeel free to update IS, if I miss something.
Comment #60
andypostLooks good to go! Thank you @voleger
Comment #61
alexpottI'm not convinced this should be here. The only place that utility.inc is loaded from is from rebuild.php. This code is rescue code and for me does not belong in a class that is autoloadable by regular Drupal. If we want to remove it from utlity.inc then I think we should consider moving it to rebuild.php. There are usages in contrib but one has to wonder why drupal_flush_all_caches() was not the correct thing for them to use - http://grep.xnddx.ru/search?text=drupal_rebuild%28&filename=
We're changing something that is internal - ie. marked with an _ to a public static function. But there is a tonne of usage in contrib - http://grep.xnddx.ru/search?text=_drupal_flush_css_js&filename= . I think we should be asking ourselves if this is the right place to put this. Or is there a core service that already interacts with this state that should be responsible for doing this. Or should we be adding a little service to do this.
Comment #63
volegerAdded service for managing query string for css and js files. In some cases the state service injected in classes, where new service used, become redundant.
Moved drupal_rebuild function into rebuild.php file.
Comment #64
volegerNeed some feedback for the last changes
Comment #65
andypostSadly merge requests provide no link in mail to check interdiff)
Comment #66
volegerComment #68
daffie commentedThe MR needs to be rebased to 9.2.x.
Comment #69
daffie commentedAll the deprecations need to be changed from 9.1.0 to 9.2.0.
Comment #70
volegerAddressed all review threads and #69 comment
Comment #71
daffie commentedAt lot of testbot failures because of: "$state parameter is deprecated since drupal:9.2.0 and removed from drupal:10.0.0" and "$query_string parameter is added since drupal:9.2.0 and is required from drupal:10.0.0".
Comment #72
volegerNeeds reroll see #2160091: drupal_rebuild() rebuilds container twice, since drupal_flush_all_caches() also rebuilds it
Comment #73
spokjeComment #74
spokjeComment #76
volegerRebased against 9.3.x branch
Comment #77
daffie commentedThe testbot is not happy.
Comment #78
sharique commented@voleger I think you need to rebase your branch.
I ran the tests and following is the results
Much less than that of the testbot.
Comment #80
andypostI think deprecation of
drupal_rebuild()could use separate issue as it used only in front controller and few places in contrib http://grep.xnddx.ru/search?text=drupal_rebuildthen we can get rid of
core/includes/utility.incin D10Comment #82
yogeshmpawarComment #83
alexpottI think this issue could do with coming in 2 parts. One that deals with the new CSS / JS query string service and converting usages of _drupal_flush_css_js() and anything that accesses the 'system.css_js_query_string' state directly. And another that deals with drupal_flush_all_caches() and drupal_rebuild().
Comment #84
alexpottAlso the change here needs to be made in light of changes to drupal_flush_all_caches(). It some ways it might be best to start a fresh - or at least copying the entire current contents of drupal_flush_all_caches() again - it now accepts a $kernel argument. And that needs to be copied over.
Comment #86
ravi.shankar commentedFixed drupal CS issue of #81, still needs work for comments #83, #84.
Comment #88
andypostas a feature
Comment #89
kim.pepperCreated a new child issue #3358336: Deprecate _drupal_flush_css_js() and create a new AssetQueryString cache service for #83 Part 1.
Comment #90
kim.pepperI'd say this issue is postponed on #3358336: Deprecate _drupal_flush_css_js() and create a new AssetQueryString cache service
Comment #92
andypostComment #93
donquixote commentedWhy not introduce events for this?
One event for "container rebuilt".
Another event for "flush all caches". This could be triggered by "container rebuilt" so subscribers only need to subscribe to one of them, not both.
In DrupalKernel::initializeContainer(), we add this:
Or maybe there is an even better place where this event should be fired.
----
Yes, I saw CONTAINER_INITIALIZE_SUBREQUEST_FINISHED, but I am not sure I understand what it does.
It looks like it has a different purpose, and does not fire on cache rebuild exclusively.
Comment #94
kim.pepper#3358336: Deprecate _drupal_flush_css_js() and create a new AssetQueryString cache service is in so un-postponing.
Comment #95
donquixote commentedNew issue to explore the events idea: #3375976: Use events to flush all caches on container rebuild
I don't think it is mutually exclusive with this one, but let's see where it goes.
Comment #99
kim.pepperI took the approach of tagged services. I think it works quite nicely. Would be interested in some early feedback before I go much further.
Comment #100
donquixote commentedInteresting. This is a valid alternative to events.
Can we make a good argument why cache tags + interface is preferable over events?
I don't have a clear opinion one way or the other, but I am curious, and I think it is good if we can describe why we do it this way.
Currently, event subscribers are more verbose, but I think we should move towards using the
#[AsEventSubscriber]attribute from symfony.Service tags + interface means that the service always needs to implement the interface, and the method always needs to have the same name.
I think in isolation it is hard to determine which is better.
Comment #101
donquixote commentedBtw, at some point we could change
drupal_rebuild()andDrupalKernelso that we call cache rebuild from the kernel instead of fromdrupal_rebuild(). But at that point we can also question other parts of the process.Comment #102
smustgrave commentedSeems a number of failures in MR 4430
Comment #103
kim.pepperHoping for some more feedback before going much further.
Comment #104
smustgrave commentedGotcha will put back to review then.
Comment #105
smustgrave commentedHave posted in #contribute to try and get some eyes but no luck so far.
Comment #106
kim.pepperThis needs an IS and CR update since #3358336: Deprecate _drupal_flush_css_js() and create a new AssetQueryString cache service went in. Might also be worth adding the options discussed here: i.e. tagged services vs events.
Comment #107
kim.pepperComment #108
catchFor me on tagged services vs. events I like the simplicity of https://git.drupalcode.org/project/drupal/-/merge_requests/4430/diffs#c8...
I also went for tagged services in #3257725: Add a cache prewarm API.
Part of this is a long-standing dislike for the Symfony Event API though, for here specifically my main reason is the Event class. There's no state to pass around here, there's no need to be able to stop propagation etc. we just want to run a method with no arguments and no return value.
Comment #109
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #110
kim.pepperRebased on 11.x
Comment #111
kim.pepperSorry @catch Do you mind pasting the code you are referring to in #108? I think the link got broken in the rebase.
Comment #112
catchThis is what I meant by the simplicity of tagged services, it very much suits having neither context to pass in nor anything to return.
Comment #113
smustgrave commentedThanks @catch. Moving to NW for that and issue tags.
Comment #114
catchThat's not a needs work issue, it's supporting the current implementation over using an event.
New symfony events with attribute subscription and no event class are a bit better than how core currently uses events, but don't think we fully support that yet.
Comment #115
kim.pepperMerge in 11.x
Comment #116
smustgrave commentedThis something that should be aiming for 10.2
Comment #117
smustgrave commentedDidn't mean to change status.
Comment #118
kim.pepperI'm not sure whether we should wait for #3257725: Add a cache prewarm API ? Is there any overlap?
Comment #119
catchDoesn't need to be postponed on #3257725: Add a cache prewarm API IMO, any overlap won't be too hard to deal with.
Comment #120
volegerRemoved mention of _drupal_flush_css_js() function as it is already deprecated.
Comment #121
volegerComment #122
smustgrave commentedSeems to have test failures.
Comment #127
gappleMR 4430 has significantly different code, but no explanation for the changes.I've rebased MR 9 from 9.4.x to 11.xI skipped over too many comments and missed context.
Comment #130
gappleI was confused by the title & summary still referencing
drupal_rebuild, which is no longer present in the latest MR (and potentially covered by prewarming in the future instead?).Updated title & summary to reflect current changes only applying
drupal_flush_all_caches