Skip to content

Commit

Permalink
Query all the tickets at once.
Browse files Browse the repository at this point in the history
Saves expensive DB queries at the expense of iterating trough
the result set twice.
  • Loading branch information
mrubinsk committed Mar 20, 2015
1 parent 227e160 commit b0b4ce2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions whups/lib/Api.php
Expand Up @@ -606,15 +606,18 @@ public function listCostObjects($criteria)
'active' => ($ticket['state_category'] != 'resolved'),
'name' => sprintf(
_("Ticket %s - %s"), $ticket['id'], $ticket['summary']));

/* If the user has an estimate attribute, use that for cost object
* hour estimates. */
$attributes = $whups_driver->getTicketAttributesWithNames($ticket['id']);
}
/* If the user has an estimate attribute, use that for cost object
* hour estimates. */
$ticket_ids = array_map(function($item) {
return $item['id'];
}, $tickets);
$att_list = $whups_driver->getTicketAttributesWithNames($ticket_ids);
foreach ($att_list as $attributes) {
foreach ($attributes as $k => $v) {
if (Horde_String::lower($k) == _("estimated time") ||
Horde_String::lower($k) == 'estimated time') {
if (!empty($v)) {
$result[$ticket['id']]['estimate'] = (double) $v;
if (strtolower($v['attribute_name']) == _("estimated time")) {
if (!empty($v['attribute_value'])) {
$result[$k['id']]['estimate'] = (double) $v['attribute_value'];
}
}
}
Expand Down

0 comments on commit b0b4ce2

Please sign in to comment.