r844: Removing the complex joins for bugs by caching user information on
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 27 May 2006 17:52:23 +0000 (17:52 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 27 May 2006 17:52:23 +0000 (17:52 +0000)
docs/changes.txt
docs/schema_changes.sql
docs/todo.txt
docs/update_bug_names.php [new file with mode: 0644]
editcomment.php
editreport.php
includes/api_bug.php
index.php
newreport.php
templates/trackerhome_bits.tpl

index 136688ccedd6ad45d17833a0b8bbd4cebbcd6740..8b8279f84b5dd4f8ce1990f9c921fd06a3fd0f9b 100644 (file)
@@ -6,6 +6,7 @@
 - Removed potential implode() warnings in showreport.php under PHP5
 - When logging out, you will be redirected to the page you were previously viewing
 - Rewrote the logging mechanism
+- Usernames are now cached in the database for bug reports to remove the need to do complex joins at runtime
 
 1.0.2
 ==================
index eeacdb65bf01b29c4d829a8f06900f4220f7183a..a5bc203bc5a383a29910f22093a6ba6fe598e856 100644 (file)
@@ -1 +1,7 @@
 ## SVN $Id$
+
+ALTER TABLE bug ADD username varchar(255) NOT NULL;
+
+ALTER TABLE bug ADD lastpostbyname varchar(255) NOT NULL;
+
+ALTER TABLE bug ADD hiddenlastpostbyname varchar(255) NOT NULL;
index 846779be722b445282d4f97e2fe0b0eecb152600..3e27406f6c3b2cbb306070a60e95188ab2d80f20 100755 (executable)
@@ -9,7 +9,6 @@ BUGTRACK 1.1
   CORE SYSTEM CHANGES
 ----------------------------------------
 - Switch to ISSO APIs
-- Cache user information into bug reports so we don't have to do mondo-joins
 
 ----------------------------------------
   BUG REPORTING/EDITING
diff --git a/docs/update_bug_names.php b/docs/update_bug_names.php
new file mode 100644 (file)
index 0000000..9e1a3a7
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+// SVN $Id$
+
+chdir('./../');
+require_once('./global.php');
+
+$userlist = array();
+$users = $db->query("SELECT userid, displayname FROM " . TABLE_PREFIX . "user");
+while ($user = $db->fetch_array($users))
+{
+       $userlist["$user[userid]"] = $user['displayname'];
+}
+
+$bugs = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug");
+while ($bug = $db->fetch_array($bugs))
+{
+       $db->query("
+               UPDATE " . TABLE_PREFIX . "bug
+               SET username = '" . $db->escape_string($userlist["$bug[userid]"]) . "',
+                       lastpostbyname = '" . $db->escape_string($userlist["$bug[lastpostby]"]) . "',
+                       hiddenlastpostbyname = '" . $db->escape_string($userlist["$bug[hiddenlastpostby]"]) . "'
+               WHERE bugid = $bug[bugid]
+       ");
+}
+
+?>
\ No newline at end of file
index 95feaee7311480626ccc9a9519f00ecb2c3155ab..4a867e0c300e48b146ed705959c382338f34f8a5 100644 (file)
@@ -81,11 +81,19 @@ if ($_POST['do'] == 'update')
                $log->add_data(true, $commentapi->objdata, array('comment', 'hidden'), false, 'comment');
                $log->add_data(false, $commentapi->values, array('comment', 'hidden'), false, 'comment');
                
-               $lastgood = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] AND !hidden ORDER BY dateline DESC");
+               $lastgood = $db->query_first("
+                       SELECT comment.* AS comment, user.displayname AS username
+                       FROM " . TABLE_PREFIX . "comment
+                       LEFT JOIN " . TABLE_PREFIX . "user AS user
+                               ON (user.userid = comment.userid)
+                       WHERE bugid = $bug[bugid]
+                               AND !hidden ORDER BY dateline DESC
+               ");
                $db->query("
                        UPDATE " . TABLE_PREFIX . "bug
                        SET hiddenlastposttime = $lastgood[dateline],
-                               hiddenlastpostby = $lastgood[userid]
+                               hiddenlastpostby = $lastgood[userid],
+                               hiddenlastpostbyname = '" . $db->escape_string($lastgood['username']) . "'
                        WHERE bugid = $bug[bugid]"
                );
                
index c41715dc8c05865f040bd4122b6982fa53844ea8..381bee447702e1a177807184e53c1893a75bf07c 100644 (file)
@@ -126,10 +126,12 @@ if ($_POST['do'] == 'update')
                $comment->set('comment',        $commenttext);
                $comment->insert();
                
-               $bugapi->set('lastposttime',            $comment->values['dateline']);
-               $bugapi->set('lastpostby',                      $bugsys->userinfo['userid']);
-               $bugapi->set('hiddenlastposttime',      $comment->values['dateline']);
-               $bugapi->set('hiddenlastpostby',        $bugsys->userinfo['userid']);
+               $bugapi->set('lastposttime',                    $comment->values['dateline']);
+               $bugapi->set('lastpostby',                              $bugsys->userinfo['userid']);
+               $bugapi->set('lastpostbyname',                  $bugsys->userinfo['displayname']);
+               $bugapi->set('hiddenlastposttime',              $comment->values['dateline']);
+               $bugapi->set('hiddenlastpostby',                $bugsys->userinfo['userid']);
+               $bugapi->set('hiddenlastpostbyname',    $bugsys->userinfo['displayname']);
                
                if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
                {
index 9f07233b7c6567f8f2a5f68c8062f4a380fa9596..67bacd157e760772d0cc6fc99df2b9211367e842 100644 (file)
@@ -43,6 +43,7 @@ class BugAPI extends API
        var $fields = array(
                'bugid'                                 => array(TYPE_UINT,     REQ_AUTO,       'verify_nozero'),
                'userid'                                => array(TYPE_UINT,     REQ_NO),
+               'username'                              => array(TYPE_STR,      REQ_NO),
                'dateline'                              => array(TYPE_UINT,     REQ_SET),
                'productid'                             => array(TYPE_UINT, REQ_YES,    ':self'),
                'componentid'                   => array(TYPE_UINT,     REQ_NO,         ':self'),
@@ -59,8 +60,10 @@ class BugAPI extends API
                'initialreport'                 => array(TYPE_UINT,     REQ_NO),
                'lastposttime'                  => array(TYPE_UINT,     REQ_NO),
                'lastpostby'                    => array(TYPE_UINT,     REQ_NO),
+               'lastpostbyname'                => array(TYPE_STR,      REQ_NO),
                'hiddenlastposttime'    => array(TYPE_UINT,     REQ_NO),
-               'hiddenlastpostby'              => array(TYPE_UINT,     REQ_NO)
+               'hiddenlastpostby'              => array(TYPE_UINT,     REQ_NO),
+               'hiddenlastpostbyname'  => array(TYPE_STR,      REQ_NO)
        );
        
        /**
index 201d58b4c6f3c9ca450e98c9b28604cc113dc3a0..b210bfe26cfeef422e782523b379be359571f780 100644 (file)
--- a/index.php
+++ b/index.php
@@ -52,17 +52,10 @@ $pagination->total = $count['count'];
 $pagination->split_pages();
 
 $bugs_fetch = $db->query("
-       SELECT bug.*, user1.displayname AS firstreport, user2.displayname AS lastpost, user3.displayname AS hiddenlastpost
-       FROM " . TABLE_PREFIX . "bug AS bug
-       LEFT JOIN " . TABLE_PREFIX . "user AS user1
-               ON (bug.userid = user1.userid)
-       LEFT JOIN " . TABLE_PREFIX . "user AS user2
-               ON (bug.lastpostby = user2.userid)
-       LEFT JOIN " . TABLE_PREFIX . "user AS user3
-               ON (bug.hiddenlastpostby = user3.userid)
-       WHERE bug.productid IN (" . fetch_on_bits('canviewbugs') . ")
+       SELECT * FROM " . TABLE_PREFIX . "bug
+       WHERE productid IN (" . fetch_on_bits('canviewbugs') . ")
                AND (!hidden OR (hidden AND productid IN (" . fetch_on_bits('canviewhidden') . ")))
-       ORDER BY bug." . ((can_perform('canviewhidden')) ? "lastposttime" : "hiddenlastposttime") . " DESC
+       ORDER BY " . (can_perform('canviewhidden') ? "lastposttime" : "hiddenlastposttime") . " DESC
        LIMIT " . $pagination->fetch_limit($pagination->page - 1) . ", " . $pagination->perpage
 );
 
@@ -79,8 +72,8 @@ while ($bug = $db->fetch_array($bugs_fetch))
        
        $bug['hiddendisplay'] = ((!can_perform('canviewhidden', $bug['productid']) AND $bug['hiddenlastposttime']) ? true : false);
        
-       $bug['lastposttime'] = (($bug['hiddendisplay']) ? $bug['hiddenlastposttime'] : $bug['lastposttime']);
-       $bug['lastpost'] = (($bug['hiddendisplay']) ? $bug['hiddenlastpost'] : $bug['lastpost']);
+       $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']);
+       $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']);
        
        $bug['lastposttime'] = $datef->format($bugsys->options['dateformat'], $bug['lastposttime']);
        
index ea89eaaf3333994228c3f2c19213977410e6cdaa..05dee84ec18ea28a1ad0dd9709cf5a6826a7ce69 100755 (executable)
@@ -52,6 +52,7 @@ if ($_POST['do'] == 'insert')
        $comment = new CommentAPI($bugsys);
        
        $bug->set('userid',                     $bugsys->userinfo['userid']);
+       $bug->set('username',           $bugsys->userinfo['displayname']);
        $bug->set('summary',            $bugsys->in['summary']);
        $bug->set('severity',           $bugsys->in['severity']);
        
@@ -101,14 +102,16 @@ if ($_POST['do'] == 'insert')
                $comment->insert();
                
                $bug = new BugAPI($bugsys); // need to destroy because update will think the insert fields need to be changed, too
-               $bug->set('bugid',                              $comment->values['bugid']);
+               $bug->set('bugid',                                      $comment->values['bugid']);
                $bug->set_condition();
-               $bug->set('dateline',                   $comment->values['dateline']);
-               $bug->set('initialreport',              $comment->insertid);
-               $bug->set('lastposttime',               $comment->values['dateline']);
-               $bug->set('lastpostby',                 $bugsys->userinfo['userid']);
-               $bug->set('hiddenlastposttime', $comment->values['dateline']);
-               $bug->set('hiddenlastpostby',   $bugsys->userinfo['userid']);
+               $bug->set('dateline',                           $comment->values['dateline']);
+               $bug->set('initialreport',                      $comment->insertid);
+               $bug->set('lastposttime',                       $comment->values['dateline']);
+               $bug->set('lastpostby',                         $bugsys->userinfo['userid']);
+               $bug->set('lastpostbyname',                     $bugsys->userinfo['displayname']);
+               $bug->set('hiddenlastposttime',         $comment->values['dateline']);
+               $bug->set('hiddenlastpostby',           $bugsys->userinfo['userid']);
+               $bug->set('hiddenlastpostbyname',       $bugsys->userinfo['displayname']);
                $bug->update();
                
                $message->redirect($lang->string('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
index 78c0fb20423605da71baa2b3486779e4f5aab9d8..700313c8d7a5a6a10a3c8637e3abc5685d85eae4 100644 (file)
@@ -4,7 +4,7 @@
        <td>$bug[bugid]</td>
        <td>
                <div><a href="showreport.php?bugid=$bug[bugid]$bug[urladd]">$bug[summary]</a></div>
-               <if condition="$bug['firstreport']"><div>$bug[firstreport]</div></if>
+               <if condition="$bug['username']"><div>$bug[username]</div></if>
        </td>
        <td>
                <div>$bug[product]</div>