Closed (fixed)
Project:
Drupal core
Version:
8.4.x-dev
Component:
content_moderation.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Oct 2017 at 01:13 UTC
Updated:
3 Dec 2017 at 22:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
amateescu commentedI also simplified
getDefaultRevisionId()which uses almost the same code.Comment #3
sam152 commentedWe have a few places throughout core where we've copied this block of code in order to support latest/pending revisions agnostic of content moderation. It would be awesome to see this moved into #2784201: Track the latest_revision and latest_revision_translation_affected ID in the entity data table for revisionable entity types, so we can fix all of these places in one go.
I have some more thoughts on that issue which I'll add shortly, it unblocks a lot of good cleanup and would allow these methods to either disappear or be @deprecated.
Edit: Also, this is awesome :D
Comment #4
sam152 commentedI've pushed some code to the other issue for review. I think the changes in #2 make sense to keep around if that approach is accepted. I'm hoping those methods will not be as needed in the rest of core, I'm thinking contexts that need the latest revision will simply choose to load it or check
isLatestRevisionon the entity itself, mitigating the need to callgetLatestRevisionIdorgetDefaultRevisionIdin the first place.There are two other methods on
ModerationInformationwhich would become redundant however, so this issue could be highjacked to cover those.If you think the other issue is going to be a long road or don't agree with that approach, just tell me to buzz off and I can RTBC #2, which looks like a great clean-up.
Comment #6
timmillwoodI seems a shame to block this issue on #2784201: Track the latest_revision and latest_revision_translation_affected ID in the entity data table for revisionable entity types. The patch in #2 is a nice advancement on it's own, could we push the changes in #4 to a follow up issue?
Comment #7
sam152 commentedHappy to take the approach in #6, the blocker could take a while to suss out.
Comment #8
timmillwoodAwesome, might be time to RTBC #2 then?
Comment #9
sam152 commentedComment #10
sam152 commentedComment #11
timmillwoodThanks for the reupload, looks good to me.
+1 for RTBC.
Comment #12
larowlanexcuse my ignorance - but doesn't EntityStorageInterface::load() return the default revision? So is this method only to avoid the entity load?
Comment #13
amateescu commented@larowlan, I think this method actually avoids a
loadUnchanged()call, which bypasses the entity cache.Comment #14
larowlanThanks
Comment #15
xjmI've been squinting at this and I can't tell how the code in HEAD is different, yet it's being changed to different things in the patch.
Comment #16
amateescu commented@xjm, the difference is that in HEAD
getDefaultRevisionId()does not callallRevisions()on the entity query, and the query's default behavior is to get the default revision. I added thecurrentRevision()call in the patch just to make it a bit more explicit.Looking around a bit I saw that we don't have dedicated test coverage for these two methods so I wrote it. The test-only patch is supposed to pass both in HEAD and with the patch.
Comment #19
xjmAh thanks @amateescu, that's what I was missing. Also +1 for the added test coverage; that helps make it clear that the refactor is correct and safe.
Committed and pushed to 8.5.x. I also cherry-picked it to 8.4.x since it's an internal cleanup and Content Moderation is in beta anyway.
Also this marks my 1000th core commit. Hooray!
Comment #20
amateescu commentedWeeee, congrats @xjm! :)
Comment #21
amateescu commentedOops..