Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part of #2068325: [META] Convert entity SQL queries to the Entity Query API. See the parent issue for details.
Comments in #59.
Comment | File | Size | Author |
---|---|---|---|
#76 | interdiff-2068333-73-76.txt | 1.28 KB | roderik |
#76 | node-entity-queries-2068333-76.patch | 23.25 KB | roderik |
Comments
Comment #1
Désiré CreditAttribution: Désiré commentedI don't see any sql queries in the menu_link module (except the \Drupal\menu_link\MenuLinkStorageController of course).
So I think this issue should be closed.
Comment #2
Désiré CreditAttribution: Désiré commentedSorry, previous comment landed on the wrong issue...
Comment #3
plachComment #4
Désiré CreditAttribution: Désiré commentedHere is a partial solution, changes only in the node.module file. It also contains some todos where are queries to change in this issue.
I'm also created a new function (node_mass_update_user_nodes()) to eliminate some code duplication.
Comment #5
Désiré CreditAttribution: Désiré commentedComment #6
plachAre you still working on this? Otherwise tomorrow we should be able to bring it forward at the Prague extended sprint.
Comment #7
Désiré CreditAttribution: Désiré commentedComment #8
plachComment #9
marcingy CreditAttribution: marcingy commentedNew patch its doesn't touch tracker or statistics yet but I am also thinking they likely don't need to be ported initially as after all if I was using mongo for storage I most definently would not be using either of those modules!
Comment #10
peximo CreditAttribution: peximo commentedThis function is no longer necessary since substituted with default entity list.
Renamed the function as userRevisions.
Comment #12
peximo CreditAttribution: peximo commented10: node-entity-move-10.patch queued for re-testing.
Comment #14
xjm(Merging "node system" and "node.module" components for 8.x; disregard.)
Comment #15
skipyT CreditAttribution: skipyT commentedhi,
I can take this issue and try to create a new patch file. I rerolled the patch file from #10, also replaced the db_selects with entity queries in the test files. But some of them can't be made with entity queries. what do you recommend? shall I let them there, I don't think that one is the good solution.
Comment #16
skipyT CreditAttribution: skipyT commentedComment #17
BerdirI don't think we need to worry about tests?
Comment #18
marcingy CreditAttribution: marcingy commentedCorrect as far as I know no need to touch tests, none of the other related issues do.
Comment #19
skipyT CreditAttribution: skipyT commentedok, then I check again my patch file and push it here.
Comment #20
skipyT CreditAttribution: skipyT commentedI used the patch file from #10 to continue to work on this.
I added a node storage controller, I replaced the SQL queries to entity queries where I was able to and if it wasn't possible I added methods in the storage controller to keep those features.
Comment #21
chx CreditAttribution: chx commentedIn lastChanged() you are missing an execute and fetchField() would be better also you can do
Comment #22
chx CreditAttribution: chx commentedAlso, please be mindful of
\ No newline at end of file
these git warnings and add a newline to the end of the new files. Thanks!And thanks for working on this, really nice to see this moving forward.
Comment #23
skipyT CreditAttribution: skipyT commentedFixed the issues found by chx and also some found by me (renamed some variables, modified documentation).
Comment #24
skipyT CreditAttribution: skipyT commentedComment #28
skipyT CreditAttribution: skipyT commentedfixed some issues, found another query to be converted, fixed that also.
Comment #30
jibran28: node-entity-queries-2068333-28.patch queued for re-testing.
Comment #32
pcambraHere's a reroll changing some signatures of the account interfaces and node interfaces used, let's see what else is missing from here.
Comment #34
pcambraThere were a couple of missing includes.
Comment #35
skipyT CreditAttribution: skipyT commentedthis seems ok, but personally I don't like the solution to call a procedural function from a storage controller. can't we find a solution to avoid this kind of code or do you think this kind of dependencies are ok?
Comment #36
pcambraJust to clarify that we're discussing about this piece of the code.
I don't like it either but I guess it should be handled in a followup, maybe making it a method of the storage controller from nodes and removing it from node.admin.inc?
Maybe related: #89181: Use queue API for node and comment, user, node multiple deletes
Comment #37
chx CreditAttribution: chx commentedI do not see why do you need to move all the procedural code into the storage controller...? ->userNodes is already public so can't we just do:
and
and then anonymizeUserRevisions would just be the update() in anonymizeUserNodes in the current patch. Already node_user_predelete() does something similar.
Comment #38
pcambraAgreed with @chx, here's a version implementing the changes proposed in #37
Comment #39
pcambraComment #40
skipyT CreditAttribution: skipyT commentedseems ok for me
Comment #41
roderikTrying to review issues @ DevDays, and learn. Relatively new to D8 core contribution, so please bear with some wordiness and feel free to tell me, if doing/saying too much/little.
done:
- reviewed the code
- reviewed the node module for outstanding stuff, obviously didn't find anything
- the scope of this issue does not require checking against 'core gates' or anything else I can think of. (I did find something that left me wondering, but I'll ask in the related meta issue.)
I wouldn't RTBC even if I did only space changes, so it's still Needs Review. But I think anyone who's seen the previous version can quickly set RTBC. It was already reviewed before me, anyway.
...but I did minor changes:
- space/indent changes
- changed 'join' to 'innerJoin' in revisionsList, for clarity. (Another innerJoin is already in there too.)
- inserted extra comment in node_user_cancel(); if node_mass_update() confuses me, it may confuse someone else too...
Comment #42
plachThanks for working on this! I was finally able to review the patch:
This change should be ok, as here we are selecting all nodes the user has access to for at least one translation, but a single
node_access()
call should be able to determine per-language access when generating the actual menu link. We need to remove the following @todo, though.Can we make the $langcode parameter optional since we are supporting it being NULL?
Why can't we implement these through entity query?
Spoke with @catch about this: we shouldn't really be doing such partial updates anymore as they bypass the Entity API. He suggests to just do a proper node (revision) save within the batch update.
The
updateType()
above is a valid exception because we cannot save a node with an invalid type.This should be Language::LANGCODE_NOT_SPECIFIED.
missing capital N
Bad indentation.
Comment #43
plachComment #44
roderikThanks for the review! I don't spot these things but can probably implement. Will do this before working further on #2068331, and take the above into account there.
Comment #45
roderikInterdiff is between the rebased patch #41 and the new one; I assume that's what people do. The difference between #41 and #41-rebased is that the menu.inc patch has fallen away: #2199381: Add \Drupal\Core\Path\PathInterface moved
menu_tree_check_access()
to Drupal\menu_link\MenuTree::checkAccess() and rewrote it to not use a database query anymore.---
re. #42:
point 1: obsoleted by the above - lucky me ;)
point 2-6 implemented; 7 not seen. Plus added some random comments in the new interface.
re. point 4:
node_mass_update()
. Not ideal, but I guess there isn't an ideal way. Comments welcome.node_mass_update()
now gets a list of node revisions to update to 0)...node_field_revision.uid
gets set to 0 butnode_revision.revision_uid
keeps the id of the now-deleted user. This also happens before applying the patch; I can't see if it's an issue that should be filed, someone is working on deletingnode_revision.revision_uid
, or whatever else. So, assuming I shouldn't create an issue for that.Comment #47
roderikTests didn't fail on my local machine, so I hope the failures go away now :/
In the meantime: rerolled after #2188613: Rename EntityStorageController to EntityStorage got committed. The comments from #45 still apply; there's just an extra renamed interface/class/file/method in the interdiff.
Comment #48
roderik*cough*
Comment #50
roderik(LOL. Maybe a 'use' statement helps before using Language::LANGCODE_NOT_SPECIFIED. Live and learn. Now just uploading and seeing what the testbot says.)
Again: comments from #45 still apply.
Comment #51
plachThanks for the update! There are still some issues though:
It seems we can remove this now.
In D8 we don't support partial entity objects. This method should return a list of revision ids that can then be used to retrieve the related revision entity objects.
Comment #52
roderik#1: d'oh! / #2: done.
revisionsList() has been replaced by revisionIds(). Points of note:
node_revision_list()
has pretty specific return arguments and actually only one caller (node_revision_overview()
) uses those. So, as discussed,node_revision_list()
has been removed;node_revision_overview()
was changed to accomodate this, and other callers are now changed to use therevisionIds()
method.Those calls are inside simpletests.
My local environments is failing tests in mysterious (possibly unrelated) ways now :/ so I'll just see if the test bot is nice to me.
Comment #53
roderik.
Comment #54
roderikOh; draft change record at [#2228895].
Comment #55
plachI am terribly sorry, I completely lost track of this. This looks fine to me now!
Here's a reroll as the patch no longer applied. Assigning to @catch since I discussed this with him.
Comment #56
plachlol
Comment #57
catchThis and others don't really need to use ->select, could just be static queries no?
I don't understand this change. tbh I don't understand the entire function.
This passes in an nid, so we could just load the node. But where this gets called, we already have the node.
Also it is loading the nodes but not checking the translated value of 'changed'.
NodeFormController::validate is one of only two places this is used:
node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime()))
That results in $node->getChangedTime() > $node->getChangedTime() after all that work it looks like.
Should just be a check on the original entity or something? We could likely remove node_last_changed() altogether.
Looks like a performance regression, but unavoidable really.
Comment #58
BerdirYes, the last changed function looks wrong, that very explicitly looks for it with a raw query.
We have an EntityChanged constraint now, which uses loadUnchanged() instead.
Comment #59
roderik#1
sure; will remember the convention.
(For consistency, I also made it explicit that userRevisions() returns a sorted list; comments still welcome.
#2
Thanks for your comments! Should have seen that this rewrite wasn't making sense / checked the actual function usage.
If I pieced all the info together correctly,
So shall I just place a @todo to delete this function later (while ignoring the fact that we ignore the $langcode argument, for now)?
Comment #60
roderikComment #62
roderikStill a noob, I know. (I guess this is the correct way to do update db_queries...)
Comment #63
roderik.
Comment #64
roderikComment #65
alexpottThe names of these functions are inconsistent - both return a list of revision IDs
how about old_type, new_type instead of _id
This function does not delete anything
Comment #66
roderikThanks. Changed . (Between resetRevisionsLanguage, unsetRevisionsLanguage and clearRevisionsLanguage, I chose the latter.)
Not changing assignee...idk...
Comment #67
plachAside from the things below it seems this is addressing the reviews above.
Also the descriptions are a bit inconsistent, they both should mention they are returning identifiers :)
This is in the wrong place, see https://drupal.org/node/1354#order. It should alse have a blank line above.
Comment #68
roderikEhm, yeah :)
Fixed, plus some more comment details.
Also reassessed the removal of node_revisions_list() (as a result of thinking about #2068331) and still concluding it should go. Draft change notice still at https://drupal.org/node/2228895.
Comment #70
roderikOh, meh.
Comment #71
plachThe comment is still a bit unclear, sorry: this is returning a set of revisions for nodes authored by the user.
I don't think we can commit this :)
Comment #72
roderikBut... why not? It's the recommended notation! :p
*slaps self* Thanks. Also for the Interface comment - better to get the details right.
Comment #73
plachThanks but...
this does not make clear yet we are talking about
$node->uid
and not$node->revision_uid
. I hope the attached patch makes it more understandable.(sorry for being picky :)
No complaints left, let's see whether @catch is happy this time :)
Comment #74
marcingy CreditAttribution: marcingy commentedAny reason why these aren't a database->update() query. I understand all the selects being static queries but I thought updates should always use ->update to deal with the differences between db drivers.
Comment #75
catchYes only static select queries should use $connection->query(), rest have to stay dynamic.
Comment #76
roderikAh.
Comment #77
marcingy CreditAttribution: marcingy commentedLooks good
Comment #78
catchCommitted/pushed to 8.x, thanks!
Comment #80
plachYay!