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.
In the nodeapi the comment statistics are loaded for every node_load.
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'load':
return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
break;
Why not make it something like this?
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'load':
if (variable_get('comment_'.$node->type, COMMENT_NODE_READ_WRITE) != COMMENT_NODE_DISABLED) {
return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
}
break;
NB: I found this in drupal 5.7 but checked and it still applies to 6 and 7-dev.
Comment | File | Size | Author |
---|---|---|---|
#43 | comment-query.patch | 2.37 KB | andypost |
#40 | comment-query2.patch | 3.13 KB | andypost |
#38 | comment-query.patch | 1.93 KB | andypost |
#37 | comment-query.patch | 1.89 KB | andypost |
#35 | comment-query-rss.patch | 2.72 KB | andypost |
Comments
Comment #1
StevenPatzThere is no patch attached.
Comment #2
R.Muilwijk CreditAttribution: R.Muilwijk commentedMy bad here it is
Comment #3
catchPatch looks sensible, however you've not indented within the new if statement.
Comment #4
catchAnd this qualifies as a bug IMO.
Comment #5
R.Muilwijk CreditAttribution: R.Muilwijk commentedSorry catch I am not really familiar yet with the categories.
New patch is up
Comment #6
R.Muilwijk CreditAttribution: R.Muilwijk commentedHuh somehow I changed it back to feature request. Back to bug report
Comment #7
Dries CreditAttribution: Dries commentedI've fixed a code style issue in your patch, and I've committed it to CVS HEAD.
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe patch is wrong: the display of comments on a particular node is governed not by the type-wide parameter
'comment_'.$node->type
but by the node-specific parameter$node->comment
. Seenode_show()
:Oh, by the way: the current comment count (as shown for example in the tracker) is actually wrong (it should be 0 when comments are disabled).
Comment #9
Dries CreditAttribution: Dries commentedYou're right, Daniel. I've rolled back the patch. This illustrates the need to write tests for patches.
Comment #10
catchWe could presumably do the same thing with if ($node->comment) right?
Comment #11
Damien Tournoud CreditAttribution: Damien Tournoud commented@Dries: No hard feelings, but it also illustrates the importance of the community review :)
@catch: completely.
Comment #12
R.Muilwijk CreditAttribution: R.Muilwijk commentednew patch making the code like this:
Comment #13
R.Muilwijk CreditAttribution: R.Muilwijk commentedCould someone please review the patch applied above.
Here are the backported patches for 6-dev and 5-dev.
Comment #14
chx CreditAttribution: chx commentedYeah -- for read only you still display them so it's a nice catch.
Comment #15
R.Muilwijk CreditAttribution: R.Muilwijk commentedthe 14th a comment code cleanup was submitted. Patch is still working however.
patch -p0 < comment_nodeapi_load_1.patch
patching file modules/comment/comment.module
Comment #16
R.Muilwijk CreditAttribution: R.Muilwijk commentedhttp://drupal.org/files/issues/comment_nodeapi_load_1.patch is ready to be comitted. Hope to get it backported to 6 soon
Comment #17
R.Muilwijk CreditAttribution: R.Muilwijk commentedThe patch only applied with a offset. I added a test for checking whether or not the comment pager works. Comment pager uses the information form nodeapi load so it should test whether or not this damages anything.
The test passes before and after applying patch. Because of this addition the status is back to patch (code needs review).
Comment #18
catchTest looks and works good, and is worthwhile in it's own right.
Comment #19
Dries CreditAttribution: Dries commentedThanks for writing these tests. Much appreciated. Committed to CVS HEAD.
Comment #20
R.Muilwijk CreditAttribution: R.Muilwijk commented6 doesn't have the .test file so the patch for 6 only contains the .module patch.
Comment #21
R.Muilwijk CreditAttribution: R.Muilwijk commentedUnfortunatly there was a little typo in my patch. For head the following patch is provided. The patch for 6.x is already fixed and valid.
Comment #22
R.Muilwijk CreditAttribution: R.Muilwijk commentedComment #23
Dries CreditAttribution: Dries commentedI've committed #22 to HEAD, but I leave #21 for Gabor to review. Lowering version to 6.x.
Thanks R.
Comment #24
samirnassar CreditAttribution: samirnassar commentedpatch at #21 is not necessary.
patch at #20 applies cleanly.
Is there a way I should test the patch further?
Comment #25
m3avrck CreditAttribution: m3avrck commentedCan't this patch be further expanded to improve the search index and results as well?
Comment #26
andypostSuppose comments should be loaded anyway because I can change $node->comment by editing node params for example to stop flame but for history purposes I need ability to watch them. This patch stops ability to load old comments and only way put duplicate code of nodeapi in own module.
Comment #27
Damien Tournoud CreditAttribution: Damien Tournoud commented@andypost: that's the way it currently works. Your module can really call
comment_nodeapi()
manually after altering the$node->comment
parameter if needed.@m3avrck: in fact it really should... so as _nodeapi($op = 'update index'), by the way.
Comment #28
m3avrck CreditAttribution: m3avrck commentedOk here are 3 patches...
Comment #29
m3avrck CreditAttribution: m3avrck commentedBumping this still needs attention & review...
Comment #30
catchSeems like the search patch should go into D7 (where it'll get more attention), then it'll just be a straight backport of all changes to Drupal 6. So bumping this back up for a bit.
Comment #32
sunThe function signature of check_markup() changed.
Those queries might as well be converted to DBTNG when touching them.
Comment #33
andypostSo this is reroll with checking for hidden comments
Comment #34
andypostBefore print link in RSS there should be a check if comments enabled
So maybe CommentRSSUnitTest should be changed? or this for another issue #335893: Option to not include comment element in Feeds
Comment #35
andypostPatch is here
Comment #37
andypostComment #38
andypostreroll against current HEAD
Comment #39
catchPatch makes sense to me. It's a slight change to search behaviour - currently we index comments with nodes even if they're hidden, but hide them on view (but you could still see the comment at comment/1 for example). Now they'll not be indexed either.
Doesn't look like there's any existing tests for comments appearing in the search index (or those nodeapi hooks in general). Would you be up for writing those? Looking at the search test, it seems like it'd be mainly copying and pasting from one of the existing tests which creates a node and indexes it, but adding a comment and changing the settings.
Comment #40
andypostSo here patch with tests included
Added test to modules/search/search.test
Logic - change node to hide comments, reindex search, try to find comment body
Comment #41
catchLooks good.
Comment #42
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. If we want to back-port this to Drupal 6 (per the tag), we'll have to re-roll.
Comment #43
andypostreroll for D6 against current 6-dev
Comment #44
R.Muilwijk CreditAttribution: R.Muilwijk commentedWorks oke for me on d6
Comment #46
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm going to guess this is a won't fix for D6, since D6 commits focus on security fixes at this point.