Add an index and avoid SELECT * for better performance

Chris Bray - September 21, 2008 - 23:38
Project:Comment CCK
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

This patch adds an index to comment_cck_revisions and removes a SELECT * to make queries quicker (5ms to 1ms in my case).

Any comments?

AttachmentSize
comment_cck.patch1.44 KB

#1

txcrew - September 23, 2008 - 23:29

How did you even get 5.x-1.x-dev to work for you? See: http://drupal.org/node/311272

I'd gladly test out the patch if it would make the mod work ;)

#2

txcrew - September 23, 2008 - 22:18

I just tried to apply the patch and I got this:

patching file comment_cck.install
patching file comment_cck.module
Hunk #1 FAILED at 137.
1 out of 1 hunk FAILED -- saving rejects to file comment_cck.module.rej

***************
*** 137,143 ****
        if (variable_get('comment_cck_node_'. $node->type, FALSE) == TRUE) {
          $fields = variable_get('comment_cck_fields_'. $node->type, array());
          $previous_text = $comment->comment;
-         $comment_revision = db_fetch_object(db_query('SELECT * FROM {comment_cck_revisions} WHERE cid = %d', $comment->cid));
          $current_node = _comment_cck_build_node((int) $comment_revision->nid, $comment_revision->vid);
          $previous_node = _comment_cck_build_node((int) $comment_revision->nid, $comment_revision->previous_vid);
          $cck_fields = content_types($node->type);
--- 137,143 ----
        if (variable_get('comment_cck_node_'. $node->type, FALSE) == TRUE) {
          $fields = variable_get('comment_cck_fields_'. $node->type, array());
          $previous_text = $comment->comment;
+         $comment_revision = db_fetch_object(db_query('SELECT cid, vid, nid, previous_vid FROM {comment_cck_revisions} WHERE cid = %d', $comment->cid));
          $current_node = _comment_cck_build_node((int) $comment_revision->nid, $comment_revision->vid);
          $previous_node = _comment_cck_build_node((int) $comment_revision->nid, $comment_revision->previous_vid);
          $cck_fields = content_types($node->type);

#3

Chris Bray - September 23, 2008 - 23:01

Hmmm, I fear I may have made the patch against a previous 5.x-1.x-dev build, rather than the current one.

I just re-rolled it and this now applies cleanly against the latest 5.x-1.x-dev.

AttachmentSize
comment_cck.patch 1.34 KB

#4

txcrew - September 23, 2008 - 23:29

Thanks!

Patch applied successfully.

From what I can tell, it seems like a good idea.

However, it still doesn't fix the functionality of the mod. Does it work for you?

txcrew

#5

Chris Bray - September 24, 2008 - 08:16

Unfortunately I don't have a test site setup at the moment and I can't upgrade the production site to the latest 5.x-1.x-dev but I'll see if I can setup a test site later and have a look for you.

#6

txcrew - September 24, 2008 - 14:21

No problem at all. Please no hurry.

If it'd be easier, could you just post the patched package of 5.x-1.x-dev you are using?

#7

txcrew - September 29, 2008 - 16:16

With many cck_comments on a single node, there will be many revisions made, does this patch also take the performance hit from having many revisions into account?

I'm assuming yes?

txcrew

#8

opensanta - May 8, 2009 - 21:59
Version:5.x-1.x-dev» 6.x-1.x-dev
Status:needs review» patch (to be ported)

@Chris Bay: Could you please update your patch to 6.x? I'm very interested in testing and applying this patch.

@txcrew: This won't solve the problem of too many revisions, but #314424: Option to disable revisions would.

#9

drewish - May 19, 2009 - 21:07
Status:patch (to be ported)» needs review

In comment_cck_update_6000() {comment_cck_revisions}.cid was made a primary key so it's got an index now. I don't know that removing the * will make nearly the difference adding the index would but here's a patch to get this moving.

AttachmentSize
comment_cck_311546.patch 1 KB
 
 

Drupal is a registered trademark of Dries Buytaert.