Skip to content

Commit

Permalink
incident/incidents: Fetch id tags already with the base query
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Jan 17, 2024
1 parent 59f7508 commit bf387fc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
1 change: 1 addition & 0 deletions application/controllers/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function indexAction(): void

$query = Incident::on(Database::get())
->with(['object', 'object.source'])
->withColumns('object.id_tags')
->filter(Filter::equal('incident.id', $id));

$this->applyRestrictions($query);
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/IncidentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function indexAction(): void
$this->addTitleTab(t('Incidents'));

$incidents = Incident::on(Database::get())
->with('object');
->with('object')
->withColumns('object.id_tags');

$limitControl = $this->createLimitControl();
$sortControl = $this->createSortControl(
Expand Down
17 changes: 17 additions & 0 deletions library/Notifications/Model/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Icinga\Module\Notifications\Model;

use Icinga\Module\Notifications\Common\Database;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;
use ipl\Sql\Connection;
use ipl\Sql\Select;

class Incident extends Model
{
Expand Down Expand Up @@ -52,6 +56,19 @@ public function getDefaultSort()
return ['incident.severity desc, incident.started_at'];
}

public static function on(Connection $db)
{
$query = parent::on($db);

$query->on(Query::ON_SELECT_ASSEMBLED, function (Select $select) use ($query) {
if (isset($query->getUtilize()['incident.object.object_id_tag'])) {
Database::registerGroupBy($query, $select);
}
});

return $query;
}

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new Binary(['object_id']));
Expand Down
38 changes: 22 additions & 16 deletions library/Notifications/Widget/Detail/IncidentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Model\Incident;
use Icinga\Module\Notifications\Model\Objects;
use Icinga\Module\Notifications\Model\Source;
use Icinga\Module\Notifications\Widget\EventSourceBadge;
use Icinga\Module\Notifications\Widget\ItemList\IncidentContactList;
use Icinga\Module\Notifications\Widget\ItemList\IncidentHistoryList;
Expand All @@ -16,7 +15,8 @@
use ipl\Html\Html;
use ipl\Html\HtmlElement;
use ipl\Html\Table;
use ipl\Stdlib\Filter;
use ipl\Orm\Query;
use ipl\Sql\Select;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;

Expand Down Expand Up @@ -93,22 +93,28 @@ protected function createRelatedObject()

protected function createHistory()
{
$history = $this->incident->incident_history
->with([
'event',
'event.object',
'event.object.source',
'contact',
'rule',
'rule_escalation',
'contactgroup',
'schedule',
'channel'
]);

$history
->withColumns('event.object.id_tags')
->on(Query::ON_SELECT_ASSEMBLED, function (Select $select) use ($history) {
Database::registerGroupBy($history, $select);
});

return [
Html::tag('h2', t('Incident History')),
new IncidentHistoryList(
$this->incident->incident_history
->with([
'event',
'event.object',
'event.object.source',
'contact',
'rule',
'rule_escalation',
'contactgroup',
'schedule',
'channel'
])
)
new IncidentHistoryList($history)
];
}

Expand Down

0 comments on commit bf387fc

Please sign in to comment.