Closed (duplicate)
Project:
Drupal core
Version:
6.x-dev
Component:
comment.module
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
6 Apr 2007 at 02:41 UTC
Updated:
4 Jun 2007 at 22:33 UTC
There is this query:
$duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND comment_md5 = '%s'", $edit['pid'], $edit['nid'], $edit['subject'], $edit['comment'])), 0);
To check for duplicates. you are searching non-indexed fields for one, and then checking for the duplication of information that has a high entropy (meaning pretty random date.
This patch creates a CHAR(32) field. When a comment is added, a md5 hash is made from the subject and comment:
$duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND comment_md5 = '%s'", $edit['pid'], $edit['nid'], md5(trim($edit['subject']) . trim($edit['comment']))), 0);
The code also re-hashes when a comment is updated. This should greatly improve comments and clean up some sql.
| Comment | File | Size | Author |
|---|---|---|---|
| comment_md5_speedup.patch | 4.78 KB | Souvent22 |
Comments
Comment #1
m3avrck commentedGreat indeed! But it can be faster:
What about doing...
That gets rid of the slower count, since it there is one result, then it's a duplicate. No need for the count.
Comment #2
m3avrck commentedHere's a patch to remove this query since it offers no real value and just slows things down: http://drupal.org/node/149339