Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
improve logic for setting up issuetype scheme, reducing number of db …
Browse files Browse the repository at this point in the history
…queries
  • Loading branch information
Daniel André Eikeland committed Dec 23, 2016
1 parent 892d1a5 commit 30b51d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions core/entities/tables/IssueTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function getAll()
return $this->select($crit);
}

public function getByIds($ids)
{
$crit = $this->getCriteria();
$crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
$crit->addWhere(self::ID, $ids, Criteria::DB_IN);
$crit->indexBy(self::ID);

return $this->select($crit);
}

public function getAllIDsByScopeID($scope_id)
{
$crit = $this->getCriteria();
Expand Down
24 changes: 16 additions & 8 deletions core/entities/tables/IssuetypeSchemeLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ public function getByIssuetypeSchemeID($issuetype_scheme_id)
{
while ($row = $res->getNextRow())
{
try
{
$i_id = $row->get(self::ISSUETYPE_ID);
$issuetype = \thebuggenie\core\entities\Issuetype::getB2DBTable()->selectById($i_id);
$return_array[$row->get(self::ISSUETYPE_ID)] = array('reportable' => (bool) $row->get(self::REPORTABLE), 'redirect' => (bool) $row->get(self::REDIRECT_AFTER_REPORTING), 'issuetype' => $issuetype);
}
catch (\Exception $e)
$i_id = $row->get(self::ISSUETYPE_ID);
$return_array[$i_id] = array('reportable' => (bool) $row->get(self::REPORTABLE), 'redirect' => (bool) $row->get(self::REDIRECT_AFTER_REPORTING));
}
if (count($return_array))
{
$i_ids = array_keys($return_array);
$issuetypes = \thebuggenie\core\entities\Issuetype::getB2DBTable()->getByIds($i_ids);
foreach ($i_ids as $i_id)
{
$this->deleteByIssuetypeID($i_id);
if (array_key_exists($i_id, $issuetypes))
{
$return_array[$i_id]['issuetype'] = $issuetypes[$i_id];
}
else
{
unset($return_array[$i_id]);
}
}
}
}
Expand Down

0 comments on commit 30b51d9

Please sign in to comment.