srchub-old

srchub-old Commit Details


Date:2014-03-24 23:15:00 (10 years 6 months ago)
Author:Natalie Adams
Branch:default
Commit:2ef32c152848
Parents: 1c4b0c50f37f
Message:Fixing issue 23 - Forge watch list SQL queries too high

Changes:
Mindefero/src/IDF/Issue.php (1 diff)
Mindefero/src/IDF/Views/Issue.php (1 diff)

File differences

indefero/src/IDF/Issue.php
128128
129129
130130
131
132
133
134
135
136
137
138
131139
132140
133141
'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"
indefero/src/IDF/Views/Issue.php
245245
246246
247247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262248
263249
264250
265251
266
252
267253
268254
269255
270
271
272
273
274
275256
257
276258
259
260
261
262
277263
278
279
280
281
282
283
284
285
286
287
288
264
265
266
267
268
269
270
271
272
273
274
275
289276
290277
291278
292
293279
294280
295281
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;

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.45038s using 20 queries.