diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-05-16 20:54:37 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-05-16 20:54:37 +0000 |
commit | 6f02738cc2ca88d01d541b9b81cc7cf860980c33 (patch) | |
tree | 81ef242e0ae747e1715142dd370450bbed651ceb | |
parent | 0b13183e097ae941db44a52b5ce5dc97faef99c2 (diff) | |
download | brdo-6f02738cc2ca88d01d541b9b81cc7cf860980c33.tar.gz brdo-6f02738cc2ca88d01d541b9b81cc7cf860980c33.tar.bz2 |
- Removed the "history"-field from the SQL table "users" and added
this information to the "users"-field in both nodes and comments.
This database/table change reduces the number of SQL queries and
makes Drupal scale better where a lot of voting/moderation takes
place. Last but not least it can be considered a new and better
foundation for future moderation metrics / algorithms. In other
words: it is plain better.
--> oops, all voting/moderation results will be lost!
--> requires database update, see "2.00-to-x.xx.sql"!
- Updated database/database.mysql
-rw-r--r-- | database/database.mysql | 71 | ||||
-rw-r--r-- | includes/comment.inc | 14 | ||||
-rw-r--r-- | includes/common.inc | 37 | ||||
-rw-r--r-- | includes/theme.inc | 14 | ||||
-rw-r--r-- | includes/user.inc | 39 | ||||
-rw-r--r-- | modules/account.module | 3 | ||||
-rw-r--r-- | modules/queue.module | 15 | ||||
-rw-r--r-- | updates/2.00-to-x.xx.sql | 5 |
8 files changed, 128 insertions, 70 deletions
diff --git a/database/database.mysql b/database/database.mysql index 0e80148c1..1940099bd 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -75,6 +75,7 @@ CREATE TABLE category ( expire int(3) DEFAULT '0' NOT NULL, comment int(2) unsigned DEFAULT '0' NOT NULL, submission int(2) unsigned DEFAULT '0' NOT NULL, + promote int(2) unsigned DEFAULT '0' NOT NULL, UNIQUE name (name), PRIMARY KEY (cid) ); @@ -112,6 +113,7 @@ CREATE TABLE comments ( score int(6) DEFAULT '0' NOT NULL, votes int(6) DEFAULT '0' NOT NULL, link varchar(16) DEFAULT '' NOT NULL, + users text NOT NULL, PRIMARY KEY (cid), KEY lid (lid) ); @@ -128,6 +130,18 @@ CREATE TABLE crons ( ); # +# Table structure for table 'cvs' +# +DROP TABLE IF EXISTS cvs; +CREATE TABLE cvs ( + user varchar(32) DEFAULT '' NOT NULL, + files text, + status int(2) DEFAULT '0' NOT NULL, + message text, + timestamp int(11) DEFAULT '0' NOT NULL +); + +# # Table structure for table 'diaries' # DROP TABLE IF EXISTS diaries; @@ -140,6 +154,17 @@ CREATE TABLE diaries ( ); # +# Table structure for table 'forum' +# +DROP TABLE IF EXISTS forum; +CREATE TABLE forum ( + lid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, + nid int(10) unsigned DEFAULT '0' NOT NULL, + body text NOT NULL, + PRIMARY KEY (lid) +); + +# # Table structure for table 'headlines' # DROP TABLE IF EXISTS headlines; @@ -195,10 +220,8 @@ CREATE TABLE modules ( DROP TABLE IF EXISTS node; CREATE TABLE node ( nid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, - lid int(10) unsigned DEFAULT '0' NOT NULL, - pid int(10) unsigned DEFAULT '0' NOT NULL, - cid int(10) unsigned DEFAULT '0' NOT NULL, - tid int(10) unsigned DEFAULT '0' NOT NULL, + lid int(10) DEFAULT '0' NOT NULL, + pid int(10) DEFAULT '0' NOT NULL, log text NOT NULL, type varchar(16) DEFAULT '' NOT NULL, title varchar(128) DEFAULT '' NOT NULL, @@ -206,12 +229,19 @@ CREATE TABLE node ( votes int(11) DEFAULT '0' NOT NULL, author int(6) DEFAULT '0' NOT NULL, status int(4) DEFAULT '1' NOT NULL, - comment int(2) DEFAULT '1' NOT NULL, timestamp int(11) DEFAULT '0' NOT NULL, + cid int(10) unsigned DEFAULT '0' NOT NULL, + tid int(10) unsigned DEFAULT '0' NOT NULL, + comment int(2) DEFAULT '1' NOT NULL, + promote int(2) DEFAULT '1' NOT NULL, + moderate text NOT NULL, + users text NOT NULL, KEY type (lid,type), KEY author (author), KEY title (title,type), - PRIMARY KEY (nid) + PRIMARY KEY (nid), + KEY promote (promote), + KEY status (status) ); # @@ -250,6 +280,33 @@ CREATE TABLE story ( ); # +# Table structure for table 'testac' +# +DROP TABLE IF EXISTS testac; +CREATE TABLE testac ( + object_id int(11), + object_title varchar(64) +); + +# +# Table structure for table 'testad' +# +DROP TABLE IF EXISTS testad; +CREATE TABLE testad ( + object_id int(11), + object_title varchar(64) +); + +# +# Table structure for table 'testae' +# +DROP TABLE IF EXISTS testae; +CREATE TABLE testae ( + object_id int(11), + object_title varchar(64) +); + +# # Table structure for table 'topic' # DROP TABLE IF EXISTS topic; @@ -257,6 +314,7 @@ CREATE TABLE topic ( tid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, pid int(10) unsigned DEFAULT '0' NOT NULL, name varchar(32) DEFAULT '' NOT NULL, + moderate text NOT NULL, UNIQUE name (name), PRIMARY KEY (tid) ); @@ -283,7 +341,6 @@ CREATE TABLE users ( last_access int(10) unsigned, last_host varchar(255), status tinyint(4) DEFAULT '0' NOT NULL, - history text NOT NULL, hash varchar(12) DEFAULT '' NOT NULL, timezone varchar(8), rating decimal(8,2), diff --git a/includes/comment.inc b/includes/comment.inc index 51aad93f1..57f2bf62e 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -31,12 +31,12 @@ function comment_moderate($moderate) { $none = $comment_votes[key($comment_votes)]; foreach ($moderate as $id=>$vote) { - if ($vote != $comment_votes[$none] && !user_get($user, "history", "c$id")) { - // update the comment's score: - $result = db_query("UPDATE comments SET score = score ". check_input($vote) .", votes = votes + 1 WHERE cid = '". check_input($id) ."'"); - - // update the user's history: - $user = user_set($user, "history", "c$id", $vote); + if ($vote != $comment_votes[$none]) { + $id = check_input($id); $vote = check_input($vote); + $comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = '$id'")); + if ($comment && !field_get($comment, "users", $user->userid)) { + $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment, "users", $user->userid, $vote) ."' WHERE cid = '$id'"); + } } } } @@ -162,7 +162,7 @@ function comment_moderation($comment) { // preview comment: $output .= " "; } - else if ($user->id && $user->userid != $comment->userid && !user_get($user, "history", "c$comment->cid")) { + else if ($user->id && $user->userid != $comment->userid && !field_get($comment, "users", $user->userid)) { // comment hasn't been moderated yet: foreach ($comment_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n"; $output .= "<SELECT NAME=\"moderate[$comment->cid]\">$options</SELECT>\n"; diff --git a/includes/common.inc b/includes/common.inc index 0a24fc927..5ca31bf36 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -199,6 +199,43 @@ function form_submit($value) { return "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". check_textfield($value) ."\">\n"; } +function field_get($object, $variable, $field) { + $data = explode(";", $object->$variable); + for (reset($data); current($data); next($data)) { + $entry = explode(":", current($data)); + if (reset($entry) == $field) $rval = end($entry); + } + return $rval; +} + +function field_set($object, $variable, $name, $value) { + $field = $object->$variable; + + if (!$value) { + // remove entry: + $data = explode(";", $field); + for (reset($data); current($data); next($data)) { + $entry = explode(":", current($data)); + if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];"; + } + } + else if (strstr($field, "$name:")) { + // found: update exsisting entry: + $data = explode(";", $field); + for (reset($data); current($data); next($data)) { + $entry = explode(":", current($data)); + if ($entry[0] == $name) $entry[1] = $value; + $rval .= "$entry[0]:$entry[1];"; + } + } + else { + // not found: + $rval = "$field$name:$value;"; + } + + return $rval; +} + $conf = conf_init(); include_once "includes/$conf.php"; diff --git a/includes/theme.inc b/includes/theme.inc index 2be12b414..269a5da2e 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -102,16 +102,14 @@ function theme_morelink($theme, $node) { } function theme_moderation_results($theme, $node) { - global $user; - - if ($user->id && $node->nid && ($user->id == $node->author || user_get($user, "history", "n$node->nid"))) { - $result = db_query("SELECT * FROM users WHERE history LIKE '%n$node->nid%'"); - while ($account = db_fetch_object($result)) { - $output .= format_username($account->userid) ." voted '". user_get($account, "history", "n$node->nid") ."'.<BR>"; + foreach (explode(";", $node->users) as $vote) { + if ($vote) { + $data = explode(":", $vote); + $output .= format_username($data[0]) ." voted '$data[1]'.<BR>"; } - - $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet."))); } + + $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet."))); } /* diff --git a/includes/user.inc b/includes/user.inc index 02038cf9b..74254dc2b 100644 --- a/includes/user.inc +++ b/includes/user.inc @@ -52,46 +52,9 @@ function user_save($account, $array) { return user_load(($account->userid ? $account->userid : $array[userid])); } -function user_get($account, $column, $field) { - $data = explode(";", $account->$column); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if (reset($entry) == $field) $rval = end($entry); - } - return $rval; -} - -function user_set($account, $column, $name, $value) { - $field = $account->$column; - - if (!$value) { - // remove entry: - $data = explode(";", $field); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];"; - } - } - else if (strstr($field, "$name:")) { - // found: update exsisting entry: - $data = explode(";", $field); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if ($entry[0] == $name) $entry[1] = $value; - $rval .= "$entry[0]:$entry[1];"; - } - } - else { - // not found: - $rval = "$field$name:$value;"; - } - - return user_save($account, array($column => $rval)); -} - function user_access($account, $section = 0) { global $user; - if ($section) return (user_get($account, "access", $section) || $account->id == 1); + if ($section) return (field_get($account, "access", $section) || $account->id == 1); else return ($account->access || $account->id == 1); } diff --git a/modules/account.module b/modules/account.module index 5f77c995b..28faf1fe3 100644 --- a/modules/account.module +++ b/modules/account.module @@ -140,8 +140,7 @@ function account_delete($name) { function account_edit_save($name, $edit) { foreach ($edit as $key=>$value) if ($key != "access") $query .= "$key = '". addslashes($value) ."', "; db_query("UPDATE users SET $query access = '' WHERE userid = '$name'"); - if ($edit[access]) foreach ($edit[access] as $key=>$value) user_set(user_load($name), "access", $value, 1); - + if ($edit[access]) foreach ($edit[access] as $key=>$value) db_query("UPDATE users SET access = '". field_set(user_load($name), "access", $value, 1) ."'"); watchdog("message", "account: modified user '$name'"); } diff --git a/modules/queue.module b/modules/queue.module index 63278a0af..25daef56f 100644 --- a/modules/queue.module +++ b/modules/queue.module @@ -18,14 +18,13 @@ function queue_score($id) { function queue_vote($id, $vote) { global $status, $user; - if (!user_get($user, "history", "n$id")) { - // Update submission's score- and votes-field: - db_query("UPDATE node SET score = score $vote, votes = votes + 1 WHERE nid = $id"); + if ($node = node_get_object(nid, $id)) { - // Update user's history record: - $user = user_set($user, "history", "n$id", $vote); + if (!field_get($node, "users", $user->userid)) { + + // Update submission's score- and votes-field: + db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node, "users", $user->userid, $vote) ."' WHERE nid = $id"); - if ($node = node_get_object(nid, $id)) { if (variable_get("post_threshold", 4, $node) <= $node->score) { node_save(array(nid => $id, status => $status[posted]), array(status)); watchdog("message", "node: posted '$node->title' - moderation"); @@ -50,7 +49,7 @@ function queue_overview() { $content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n"; $content .= " <TR><TH>". t("Subject") ."</TH><TH>". t("Author") ."</TH><TH>". t("Type") ."</TH><TH>". t("Score") ."</TH></TR>\n"; while ($node = db_fetch_object($result)) { - if ($user->id == $node->author || user_get($user, "history", "n$node->nid")) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n"; + if ($user->id == $node->author || field_get($node, "users", $user->userid)) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n"; else $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\"><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". t("vote") ."</A></TD></TR>\n"; } $content .= "</TABLE>\n"; @@ -66,7 +65,7 @@ function queue_node($id) { $node = node_get_object(nid, $id); - if ($user->id == $node->author || user_get($user, "history", "n$node->nid")) { + if ($user->id == $node->author || field_get($node, "users", $user->userid)) { header("Location: node.php?id=$node->nid"); } else { diff --git a/updates/2.00-to-x.xx.sql b/updates/2.00-to-x.xx.sql index 24365dd57..50b9e851a 100644 --- a/updates/2.00-to-x.xx.sql +++ b/updates/2.00-to-x.xx.sql @@ -136,3 +136,8 @@ ALTER TABLE node ADD moderate TEXT NOT NULL; # 10/05/2001: ALTER TABLE topic ADD moderate TEXT NOT NULL; + +# 16/05/2001 +ALTER TABLE node ADD users TEXT NOT NULL; +ALTER TABLE comments ADD users TEXT NOT NULL; +ALTER TABLE users DROP history; |