### Eclipse Workspace Patch 1.0
#P fud
Index: FUDforum/src/cookies.inc.t
===================================================================
RCS file: /cvsroot/foundation/fud/FUDforum/src/cookies.inc.t,v
retrieving revision 1.2
diff -u -r1.2 cookies.inc.t
--- FUDforum/src/cookies.inc.t 9 May 2011 13:39:39 -0000 1.2
+++ FUDforum/src/cookies.inc.t 9 May 2011 19:06:28 -0000
@@ -54,7 +54,7 @@
$q_opt = 's.id='. $id;
}
- $u = db_sab('SELECT
+ $u = db_sab('SELECT /* USE MASTER */
s.id AS sid, s.ses_id, s.data, s.returnto, s.sys_id,
t.id AS theme_id, t.lang, t.name AS theme_name, t.locale, t.theme, t.pspell_lang, t.theme_opt,
u.alias, u.posts_ppg, u.time_zone, u.sig, u.last_visit, u.last_read, u.cat_collapse_status, u.users_opt, u.posted_msg_count, u.topics_per_page,
Index: FUDforum/src/db.inc.t
===================================================================
RCS file: /cvsroot/foundation/fud/FUDforum/src/db.inc.t,v
retrieving revision 1.3
diff -u -r1.3 db.inc.t
--- FUDforum/src/db.inc.t 9 May 2011 15:23:29 -0000 1.3
+++ FUDforum/src/db.inc.t 9 May 2011 19:06:28 -0000
@@ -2,7 +2,7 @@
/**
* copyright : (C) 2001-2010 Advanced Internet Designs Inc.
* email : forum@prohost.org
-* $Id: db.inc.t,v 1.3 2011/05/09 15:23:29 droy Exp $
+* $Id: db.inc,v 1.3 2011/05/09 13:39:41 droy Exp $
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -133,6 +133,8 @@
$GLOBALS['__DB_INC_INTERNALS__']['last_time'] = ($e - $s);
$GLOBALS['__DB_INC_INTERNALS__']['total_sql_time'] += $GLOBALS['__DB_INC_INTERNALS__']['last_time'];
$GLOBALS['__DB_INC_INTERNALS__']['last_query'] = $query;
+ array_walk( debug_backtrace(), create_function( '$a,$b', 'print "
". $a[\'file\'] . ":{$a[\'line\']} {$a[\'function\']} ()";' ) );
+
echo '
'. preg_replace('!\s+!', ' ', $query) .''; echo '
query count: '. $GLOBALS['__DB_INC_INTERNALS__']['query_count'] .' time taken: '. $GLOBALS['__DB_INC_INTERNALS__']['last_time'] .''; Index: FUDforum/src/fileio.inc.t =================================================================== RCS file: /cvsroot/foundation/fud/FUDforum/src/fileio.inc.t,v retrieving revision 1.2 diff -u -r1.2 fileio.inc.t --- FUDforum/src/fileio.inc.t 9 May 2011 13:39:39 -0000 1.2 +++ FUDforum/src/fileio.inc.t 9 May 2011 19:06:28 -0000 @@ -12,7 +12,8 @@ function read_msg_body($off, $len, $id) { if ($off == -1) { // Fetch from DB and return. - return q_singleval('SELECT data FROM {SQL_TABLE_PREFIX}msg_store WHERE id='. $id); + # fetch from master, since data is read after a new post + return q_singleval('SELECT /* USE MASTER */ data FROM {SQL_TABLE_PREFIX}msg_store WHERE id='. $id); } if (!$len) { // Empty message. Index: FUDforum/src/msg.php.t =================================================================== RCS file: /cvsroot/foundation/fud/FUDforum/src/msg.php.t,v retrieving revision 1.3 diff -u -r1.3 msg.php.t --- FUDforum/src/msg.php.t 9 May 2011 14:22:57 -0000 1.3 +++ FUDforum/src/msg.php.t 9 May 2011 19:06:28 -0000 @@ -65,7 +65,8 @@ */ make_perms_query($fields, $join); - $frm = db_sab('SELECT + # Fetch from master since we may be loading a message that was just posted moments ago + $frm = db_sab('SELECT /* USE MASTER */ c.id AS cat_id, f.name, m.subject, Index: FUDforum/src/th_adm.inc.t =================================================================== RCS file: /cvsroot/foundation/fud/FUDforum/src/th_adm.inc.t,v retrieving revision 1.2 diff -u -r1.2 th_adm.inc.t --- FUDforum/src/th_adm.inc.t 9 May 2011 13:39:39 -0000 1.2 +++ FUDforum/src/th_adm.inc.t 9 May 2011 19:06:28 -0000 @@ -34,7 +34,7 @@ db_lock('{SQL_TABLE_PREFIX}poll WRITE, '. $lock .' WRITE, {SQL_TABLE_PREFIX}thread WRITE, {SQL_TABLE_PREFIX}forum WRITE, {SQL_TABLE_PREFIX}msg WRITE'); $ll = 1; } - $msg_count = q_singleval('SELECT count(*) FROM {SQL_TABLE_PREFIX}thread LEFT JOIN {SQL_TABLE_PREFIX}msg ON {SQL_TABLE_PREFIX}msg.thread_id={SQL_TABLE_PREFIX}thread.id WHERE {SQL_TABLE_PREFIX}msg.apr=1 AND {SQL_TABLE_PREFIX}thread.id='. $id); + $msg_count = q_singleval('SELECT /* USE MASTER */ count(*) FROM {SQL_TABLE_PREFIX}thread LEFT JOIN {SQL_TABLE_PREFIX}msg ON {SQL_TABLE_PREFIX}msg.thread_id={SQL_TABLE_PREFIX}thread.id WHERE {SQL_TABLE_PREFIX}msg.apr=1 AND {SQL_TABLE_PREFIX}thread.id='. $id); q('UPDATE {SQL_TABLE_PREFIX}thread SET forum_id='. $to_forum .' WHERE id='. $id); q('UPDATE {SQL_TABLE_PREFIX}forum SET post_count=post_count-'. $msg_count .' WHERE id='. $forum_id); @@ -53,7 +53,7 @@ rebuild_forum_view_ttl($forum_id); rebuild_forum_view_ttl($to_forum); - $p = db_all('SELECT poll_id FROM {SQL_TABLE_PREFIX}msg WHERE thread_id='. $id .' AND apr=1 AND poll_id>0'); + $p = db_all('SELECT /* USE MASTER */ poll_id FROM {SQL_TABLE_PREFIX}msg WHERE thread_id='. $id .' AND apr=1 AND poll_id>0'); if ($p) { q('UPDATE {SQL_TABLE_PREFIX}poll SET forum_id='. $to_forum .' WHERE id IN('. implode(',', $p) .')'); } @@ -66,7 +66,7 @@ function __th_cron_emu($forum_id, $run=1) { /* Let's see if we have sticky threads that have expired. */ - $exp = db_all('SELECT {SQL_TABLE_PREFIX}thread.id FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' + $exp = db_all('SELECT /* USE MASTER */ {SQL_TABLE_PREFIX}thread.id FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' INNER JOIN {SQL_TABLE_PREFIX}thread ON {SQL_TABLE_PREFIX}thread.id={SQL_TABLE_PREFIX}tv_'. $forum_id .'.thread_id INNER JOIN {SQL_TABLE_PREFIX}msg ON {SQL_TABLE_PREFIX}thread.root_msg_id={SQL_TABLE_PREFIX}msg.id WHERE {SQL_TABLE_PREFIX}tv_'. $forum_id .'.id>'. (q_singleval('SELECT seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' ORDER BY seq DESC LIMIT 1') - 50).' @@ -132,7 +132,7 @@ } /* Get position. */ - if (($pos = q_singleval('SELECT seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE thread_id='. $th))) { + if (($pos = q_singleval('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE thread_id='. $th))) { q('DELETE FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE thread_id='. $th); /* Move every one down one, if placed after removed topic. */ q('UPDATE {SQL_TABLE_PREFIX}tv_'. $forum_id .' SET seq=seq-1 WHERE seq>'. $pos); @@ -154,7 +154,7 @@ db_lock('{SQL_TABLE_PREFIX}tv_'. $forum_id .' WRITE'); } - list($max,$iss) = db_saq('SELECT seq,iss FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' ORDER BY seq DESC LIMIT 1'); + list($max,$iss) = db_saq('SELECT /* USE MASTER */ seq,iss FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' ORDER BY seq DESC LIMIT 1'); if ((!$sticky && $iss) || $iss >=8) { /* Sub-optimal case, non-sticky topic and thre are stickies in the forum. */ /* Find oldest sticky message. */ if ($sticky && $iss >= 8) { Index: FUDforum/src/th_nav.inc.t =================================================================== RCS file: /cvsroot/foundation/fud/FUDforum/src/th_nav.inc.t,v retrieving revision 1.2 diff -u -r1.2 th_nav.inc.t --- FUDforum/src/th_nav.inc.t 9 May 2011 13:39:39 -0000 1.2 +++ FUDforum/src/th_nav.inc.t 9 May 2011 19:06:28 -0000 @@ -12,14 +12,14 @@ function get_prev_next_th_id($frm_id, $th, &$prev, &$next) { $next = $prev = ''; - $id = q_singleval('SELECT seq FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' WHERE thread_id='. $th); + $id = q_singleval('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' WHERE thread_id='. $th); if (!$id) { return; } $nn = $np = 0; - $c = uq('SELECT m.id, m.subject, tv.seq, t.moved_to FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' tv INNER JOIN {SQL_TABLE_PREFIX}thread t ON tv.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}msg m ON t.root_msg_id=m.id WHERE tv.seq IN('. ($id - 1) .', '. ($id + 1) .')'); + $c = uq('SELECT /* USE MASTER */ m.id, m.subject, tv.seq, t.moved_to FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' tv INNER JOIN {SQL_TABLE_PREFIX}thread t ON tv.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}msg m ON t.root_msg_id=m.id WHERE tv.seq IN('. ($id - 1) .', '. ($id + 1) .')'); while ($r = db_rowarr($c)) { if ($r[2] < $id) { if ($r[3]) { /* Moved topic, let's try to find another, */ @@ -36,11 +36,11 @@ unset($c); if ($np) { - $r = db_saq('SELECT m.id, m.subject FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' tv INNER JOIN {SQL_TABLE_PREFIX}thread t ON tv.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}msg m ON t.root_msg_id=m.id WHERE tv.seq IN('. ($id - 10) .', '. ($id - 2) .') ORDER BY tv.seq ASC LIMIT 1'); + $r = db_saq('SELECT /* USE MASTER */ m.id, m.subject FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' tv INNER JOIN {SQL_TABLE_PREFIX}thread t ON tv.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}msg m ON t.root_msg_id=m.id WHERE tv.seq IN('. ($id - 10) .', '. ($id - 2) .') ORDER BY tv.seq ASC LIMIT 1'); $prev = '{TEMPLATE: prev_thread_link}'; } if ($nn) { - $r = db_saq('SELECT m.id, m.subject FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' tv INNER JOIN {SQL_TABLE_PREFIX}thread t ON tv.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}msg m ON t.root_msg_id=m.id WHERE tv.seq IN('. ($id + 2) .', '. ($id + 10) .') ORDER BY tv.seq DESC LIMIT 1'); + $r = db_saq('SELECT /* USE MASTER */ m.id, m.subject FROM {SQL_TABLE_PREFIX}tv_'. $frm_id .' tv INNER JOIN {SQL_TABLE_PREFIX}thread t ON tv.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}msg m ON t.root_msg_id=m.id WHERE tv.seq IN('. ($id + 2) .', '. ($id + 10) .') ORDER BY tv.seq DESC LIMIT 1'); $next = '{TEMPLATE: next_thread_link}'; } } Index: FUDforum/src/tree.php.t =================================================================== RCS file: /cvsroot/foundation/fud/FUDforum/src/tree.php.t,v retrieving revision 1.2 diff -u -r1.2 tree.php.t --- FUDforum/src/tree.php.t 9 May 2011 13:39:39 -0000 1.2 +++ FUDforum/src/tree.php.t 9 May 2011 19:06:28 -0000 @@ -51,7 +51,8 @@ */ make_perms_query($fields, $join); - $frm = db_sab('SELECT + # Fetch from master since we may be loading a message that was just posted moments ago? + $frm = db_sab('SELECT /* USE MASTER */ c.id AS cat_id, f.name, m.subject, Index: FUDforum/src/users.inc.t =================================================================== RCS file: /cvsroot/foundation/fud/FUDforum/src/users.inc.t,v retrieving revision 1.2 diff -u -r1.2 users.inc.t --- FUDforum/src/users.inc.t 9 May 2011 13:39:39 -0000 1.2 +++ FUDforum/src/users.inc.t 9 May 2011 19:06:28 -0000 @@ -788,8 +788,8 @@ function user_set_post_count($uid) { - $pd = db_saq('SELECT MAX(id),count(*) FROM {SQL_TABLE_PREFIX}msg WHERE poster_id='. $uid .' AND apr=1'); - $level_id = (int) q_singleval('SELECT id FROM {SQL_TABLE_PREFIX}level WHERE post_count <= '. $pd[1] .' ORDER BY post_count DESC LIMIT 1'); + $pd = db_saq('SELECT /* USE MASTER */ MAX(id),count(*) FROM {SQL_TABLE_PREFIX}msg WHERE poster_id='. $uid .' AND apr=1'); + $level_id = (int) q_singleval('SELECT /* USE MASTER */ id FROM {SQL_TABLE_PREFIX}level WHERE post_count <= '. $pd[1] .' ORDER BY post_count DESC LIMIT 1'); q('UPDATE {SQL_TABLE_PREFIX}users SET u_last_post_id='. (int)$pd[0] .', posted_msg_count='. (int)$pd[1] .', level_id='. $level_id .' WHERE id='. $uid); }