Fixing issue 23 - Forge watch list SQL queries too high

master
Nathan Adams 2014-03-24 23:15:04 -05:00
parent 1a9c4132c2
commit 0d6b904cd6
2 changed files with 26 additions and 32 deletions

View File

@ -128,6 +128,14 @@ class IDF_Issue extends Pluf_Model
'where' => '( lcname = "new" or lcname = "accepted" or lcname = "started" )',
'join' => "INNER JOIN " . $tagtbl . " on " . $this->getSqlTable() . ".status = " . $tagtbl . ".id"
),
'project_find_open' => array (
'where' => '( lcname = "new" or lcname = "accepted" or lcname = "started" )',
'join' => "INNER JOIN " . $tagtbl . " on " . $this->getSqlTable() . ".status = " . $tagtbl . ".id"
),
'project_find_closed' => array (
'where' => '( lcname = "fixed" or lcname = "verified" or lcname = "invalid" or lcname = "wontfix" )',
'join' => "INNER JOIN " . $tagtbl . " on " . $this->getSqlTable() . ".status = " . $tagtbl . ".id"
),
'project_find_private' => array (
'where' => 'private = 0 AND ( lcname = "new" or lcname = "accepted" or lcname = "started" )',
'join' => "INNER JOIN " . $tagtbl . " on " . $this->getSqlTable() . ".status = " . $tagtbl . ".id INNER JOIN " . $projtbl . " ON " . $this->getSqlTable() . ".project = " . $projtbl . ".id"

View File

@ -245,51 +245,37 @@ class IDF_Views_Issue
public $forgeWatchList_precond = array('Pluf_Precondition::loginRequired');
public function forgeWatchList($request, $match)
{
$otags = array();
$ctags = array();
// Note that this approach does not scale, we will need to add
// a table to cache the meaning of the tags for large forges.
foreach (IDF_Views::getProjects($request->user) as $project) {
$otags = array_merge($otags, $project->getTagIdsByStatus('open'));
}
foreach (IDF_Views::getProjects($request->user) as $project) {
$ctags = array_merge($ctags, $project->getTagIdsByStatus('closed'));
}
if (count($otags) == 0) $otags[] = 0;
if (count($ctags) == 0) $ctags[] = 0;
// Get the id list of issue in the user watch list (for all projects !)
$db =& Pluf::db();
$sql_results = $db->select('SELECT idf_issue_id as id FROM '.Pluf::f('db_table_prefix', '').'idf_issue_pluf_user_assoc WHERE pluf_user_id='.$request->user->id);
$issue_ids = array(0);
foreach ($sql_results as $id) {
$issue_ids[] = $id['id'];
$issue_ids[] = $id['id'];
}
$issue_ids = implode (',', $issue_ids);
// Count open and close issues
$sql = new Pluf_SQL('id IN ('.$issue_ids.') AND status IN ('.implode(', ', $otags).')', array());
$nb_open = Pluf::factory('IDF_Issue')->getCount(array('filter'=>$sql->gen()));
$sql = new Pluf_SQL('id IN ('.$issue_ids.') AND status IN ('.implode(', ', $ctags).')', array());
$nb_closed = Pluf::factory('IDF_Issue')->getCount(array('filter'=>$sql->gen()));
$f_sql = new Pluf_SQL(Pluf::factory("IDF_Issue")->getSqlTable() . '.id IN ('.$issue_ids.')', array());
// Generate a filter for the paginator
$nb_open = Pluf::factory("IDF_Issue")->getCount(array('view'=>'project_find_open', 'filter'=>$f_sql->gen()));
$nb_closed = Pluf::factory("IDF_Issue")->getCount(array('view'=>'project_find_closed', 'filter'=>$f_sql->gen()));
$pag = new Pluf_Paginator(new IDF_Issue());
switch ($match[1]) {
case 'closed':
$title = sprintf(__('Watch List: Closed Issues'));
$summary = __('This table shows the closed issues in your watch list.');
$f_sql = new Pluf_SQL('id IN ('.$issue_ids.') AND status IN ('.implode(', ', $ctags).')', array());
break;
case 'open':
default:
$title = sprintf(__('Watch List: Open Issues'));
$summary = __('This table shows the open issues in your watch list.');
$f_sql = new Pluf_SQL('id IN ('.$issue_ids.') AND status IN ('.implode(', ', $otags).')', array());
break;
case 'closed':
$pag->model_view = 'project_find_closed';
$title = sprintf(__('Watch List: Closed Issues'));
$summary = __('This table shows the closed issues in your watch list.');
//$f_sql = new Pluf_SQL(Pluf::factory("IDF_Issue")->getList(array('view' => ))
break;
case 'open':
default:
$pag->model_view = 'project_find_open';
$title = sprintf(__('Watch List: Open Issues'));
$summary = __('This table shows the open issues in your watch list.');
break;
}
// Paginator to paginate the issues
$pag = new Pluf_Paginator(new IDF_Issue());
$pag->class = 'recent-issues';
$pag->item_extra_props = array('current_user' => $request->user);
$pag->summary = $summary;