Commit 7af49ab2 authored by Dries's avatar Dries

- Committed Marco's comment module patch:

    + Dramatically improves performance of large discussions/threads: only
      very few SQL queries are required.
    + Replaces custom pager with standard pager.

  Modifications by me:

    + Reworded some code comments.
    + Removed dependencies on pager internals.
parent ab6db286
...@@ -83,6 +83,7 @@ CREATE TABLE [dbo].[comments] ( ...@@ -83,6 +83,7 @@ CREATE TABLE [dbo].[comments] (
[link] [varchar] (16) NULL , [link] [varchar] (16) NULL ,
[score] [int] NOT NULL , [score] [int] NOT NULL ,
[status] [tinyint] NOT NULL , [status] [tinyint] NOT NULL ,
[thread] [varchar] (255) NOT NULL ,
[users] [varchar] (8000) NULL [users] [varchar] (8000) NULL
) ON [PRIMARY] ) ON [PRIMARY]
GO GO
......
...@@ -123,6 +123,7 @@ CREATE TABLE comments ( ...@@ -123,6 +123,7 @@ CREATE TABLE comments (
link varchar(16) NOT NULL default '', link varchar(16) NOT NULL default '',
score integer NOT NULL default '0', score integer NOT NULL default '0',
status smallint NOT NULL default '0', status smallint NOT NULL default '0',
thread vharchar(255) NOT NULL,
users text default '', users text default '',
PRIMARY KEY (cid) PRIMARY KEY (cid)
); );
......
This diff is collapsed.
This diff is collapsed.
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
"2003-05-31" => "update_55", "2003-05-31" => "update_55",
"2003-06-04" => "update_56", "2003-06-04" => "update_56",
"2003-06-08" => "update_57", "2003-06-08" => "update_57",
"2003-06-08: first update since Drupal 4.2.0 release" => "update_58" "2003-06-08: first update since Drupal 4.2.0 release" => "update_58",
"2003-08-05" => "update_59"
); );
function update_32() { function update_32() {
...@@ -270,6 +271,76 @@ function update_58() { ...@@ -270,6 +271,76 @@ function update_58() {
update_sql("ALTER TABLE node ADD path varchar(250) NULL default ''"); update_sql("ALTER TABLE node ADD path varchar(250) NULL default ''");
} }
function update_59() {
update_sql("ALTER TABLE comments ADD thread VARCHAR(255) NOT NULL");
$result = db_query("SELECT DISTINCT(nid) FROM comments WHERE thread = ''");
while ($node = db_fetch_object($result)) {
$result2 = db_query("SELECT cid, pid FROM comments where nid = '%d' ORDER BY timestamp", $node->nid);
$comments = array();
while ($comment = db_fetch_object($result2)) {
$comments[$comment->cid] = $comment;
}
$structure = array();
$structure = _update_thread_structure($comments, 0, -1, $structure);
foreach ($structure as $cid => $thread) {
$new_parts = array();
foreach(explode(".", $thread) as $part) {
if ($part > 9) {
$start = substr($part, 0, strlen($part) - 1);
$end = substr($part, -1, 1);
$new_parts[] = str_repeat("9", $start).$end;
}
else {
$new_parts[] = $part;
}
}
$thread = implode(".", $new_parts);
db_query("UPDATE comments SET thread = '%s' WHERE cid = '%d'", $thread."/", $comments[$cid]->cid);
}
}
}
function _update_thread_structure($comments, $pid, $depth, $structure) {
$depth++;
foreach ($comments as $key => $comment) {
if ($comment->pid == $pid) {
if ($structure[$comment->pid]) {
$structure[$comment->cid] = $structure[$comment->pid]."."._update_next_thread($structure, $structure[$comment->pid]);
}
else {
$structure[$comment->cid] = _update_next_thread($structure, "");
}
$structure = _update_thread_structure($comments, $comment->cid, $depth, $structure);
}
}
return $structure;
}
function _update_next_thread($structure, $parent) {
do {
$val++;
if ($parent) {
$thread = "$parent.$val";
}
else {
$thread = $val;
}
} while (array_search($thread, $structure));
return $val;
}
/* /*
** System functions ** System functions
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment