Problem/Motivation
In #2939505: Forum index does not update if new sub-forums are added we're merging tags from 3 sources which results in really ugly code...
Cache::mergeTags(Cache::mergeTags($this->nodeEntityTypeDefinition->getListCacheTags(), $this->commentEntityTypeDefinition->getListCacheTags()), $this->taxonomyTermEntityTypeDefinition->getListCacheTags()),
Proposed resolution
Given the importance of merge cache metadata easily let's take advantage of variadics to make this easier...
Cache::mergeTags($this->nodeEntityTypeDefinition->getListCacheTags(), $this->commentEntityTypeDefinition->getListCacheTags(), $this->taxonomyTermEntityTypeDefinition->getListCacheTags()),
Remaining tasks
User interface changes
API changes
API widened to accept more arguments (of the same type) for:
\Drupal\Core\Cache\Cache::mergeTags()
\Drupal\Core\Cache\Cache::mergeMaxAges()
\Drupal\Core\Cache\Cache::mergeContexts()
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#19 | 3125032-2-19.patch | 7.18 KB | alexpott |
#19 | 16-19-interdiff.txt | 454 bytes | alexpott |
Comments
Comment #2
alexpottComment #3
alexpottA little bit more elegant.
Comment #4
alexpottAnd a little bit more.
Comment #5
joachim CreditAttribution: joachim commentedLooks good, just a docs clarity problem:
Should these say 'Cache contexts arrayS to merge.'? The other param that has become variadic is being changed from saying 'value' to 'values'.
Comment #6
Neslee Canil PintoComment #7
alexpottThis is wrong it should be
int ...
- each argument is not an array - it's an int.Comment #8
Neslee Canil PintoComment #9
longwaveMaybe nitpicking but NULL feels like a better thing to use to represent a missing value, I had to read this twice before I figured out what was going on here but I think NULL would make it clearer from the data provider alone.
edit: or even, just pass $a, $b and optionally $c as a single array argument, and use the splat operator in testMergeMaxAges() too!
Comment #10
jungleAdopted this approach.
Comment #11
longwaveWe could also change testMergeTags() the same way rather than adding a separate test method?
Also slightly surprised that CacheTest covers tags and max ages but not contexts - I can't find a unit test for mergeContexts, is adding basic coverage for that out of scope?
Comment #12
jungleComment #13
jungle\Drupal\Tests\Core\Cache\CacheTest::validateTagsProvider()
seems not being used.Should the variable be added right after
...
?Comment #14
longwaveNow we can just roll this into mergeTagsProvider()
Comment #15
jungleAddressed #14, file a new issue for #13.1 if necessary.
Comment #16
jungleA wrong patch uploaded in #15
Comment #17
longwaveDo we use the variable name or not in variadic @params? The coding standards docs do not say.
Comment #18
alexpottRe #17 we can't use the variable name...our PHPCS implementation will moan lots and lots...
Comment #19
alexpott#16 fails PHPCS with
Comment #20
longwaveAll looks good - new functionality plus improved test coverage.
Comment #22
longwaveRandom fail in FieldLayoutTest
Comment #23
andypostFor API changes
Comment #24
jungleChange Record added, setting back to RTBC
Comment #26
catchCommitted/pushed to 9.1.x, thanks!
I'm a bit borderline on backporting this to 8.9.x, but leaving in 9.1.x for now since it's an obvious API addition even if there are no bc issues as such.
Comment #27
jungle@catch, thank you for committing!
Should the CR associated be published? And as a reminder, introduced in branch and
Introduced in version
should be adjusted before publishing.Comment #28
Wim LeersOMG so nice! 😍