From ec89fe0024a2702a9da185d24844b2a3516164b7 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 7 Feb 2020 15:49:21 +0100 Subject: [PATCH 1/2] Don't join `service.host[.state]` in history queries --- application/controllers/HistoryController.php | 2 -- application/controllers/NotificationsController.php | 2 -- application/controllers/ServiceController.php | 2 -- library/Icingadb/Widget/ItemList/HistoryListItem.php | 2 +- library/Icingadb/Widget/ItemList/NotificationListItem.php | 2 +- 5 files changed, 2 insertions(+), 8 deletions(-) diff --git a/application/controllers/HistoryController.php b/application/controllers/HistoryController.php index fbd676b0..e41e8144 100644 --- a/application/controllers/HistoryController.php +++ b/application/controllers/HistoryController.php @@ -22,8 +22,6 @@ class HistoryController extends Controller 'host.state', 'service', 'service.state', - 'service.host', - 'service.host.state', 'comment', 'downtime', 'notification', diff --git a/application/controllers/NotificationsController.php b/application/controllers/NotificationsController.php index 3a8549e3..cf834325 100644 --- a/application/controllers/NotificationsController.php +++ b/application/controllers/NotificationsController.php @@ -21,8 +21,6 @@ class NotificationsController extends Controller 'host', 'host.state', 'service', - 'service.host', - 'service.host.state', 'service.state' ]); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 623b4b8c..545a8eed 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -122,8 +122,6 @@ class ServiceController extends Controller 'host.state', 'service', 'service.state', - 'service.host', - 'service.host.state', 'comment', 'downtime', 'notification', diff --git a/library/Icingadb/Widget/ItemList/HistoryListItem.php b/library/Icingadb/Widget/ItemList/HistoryListItem.php index cd1db4c7..5166fbcd 100644 --- a/library/Icingadb/Widget/ItemList/HistoryListItem.php +++ b/library/Icingadb/Widget/ItemList/HistoryListItem.php @@ -166,7 +166,7 @@ class HistoryListItem extends CommonListItem if ($this->item->object_type === 'host') { $link = $this->createHostLink($this->item->host, true); } else { - $link = $this->createServiceLink($this->item->service, $this->item->service->host, true); + $link = $this->createServiceLink($this->item->service, $this->item->host, true); } $title->add([Html::tag('br'), $link]); diff --git a/library/Icingadb/Widget/ItemList/NotificationListItem.php b/library/Icingadb/Widget/ItemList/NotificationListItem.php index e4a38415..f3544247 100644 --- a/library/Icingadb/Widget/ItemList/NotificationListItem.php +++ b/library/Icingadb/Widget/ItemList/NotificationListItem.php @@ -105,7 +105,7 @@ class NotificationListItem extends CommonListItem if ($this->item->object_type === 'host') { $link = $this->createHostLink($this->item->host, true); } else { - $link = $this->createServiceLink($this->item->service, $this->item->service->host, true); + $link = $this->createServiceLink($this->item->service, $this->item->host, true); } $title->add($link); From 9fc88e28c68643204541aa5350ce976f34a37d06 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 7 Feb 2020 15:50:55 +0100 Subject: [PATCH 2/2] Join hosts and services with an INNER join in history queries Otherwise history entries of removed objects are fetched. --- library/Icingadb/Model/CommentHistory.php | 4 ++-- library/Icingadb/Model/DowntimeHistory.php | 4 ++-- library/Icingadb/Model/History.php | 4 ++-- library/Icingadb/Model/NotificationHistory.php | 4 ++-- library/Icingadb/Model/StateHistory.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/library/Icingadb/Model/CommentHistory.php b/library/Icingadb/Model/CommentHistory.php index 11c74baf..d69bfc0c 100644 --- a/library/Icingadb/Model/CommentHistory.php +++ b/library/Icingadb/Model/CommentHistory.php @@ -57,7 +57,7 @@ class CommentHistory extends Model { $relations->belongsTo('endpoint', Endpoint::class); $relations->belongsTo('environment', Environment::class); - $relations->belongsTo('host', Host::class)->setJoinType('LEFT'); - $relations->belongsTo('service', Service::class)->setJoinType('LEFT'); + $relations->belongsTo('host', Host::class); + $relations->belongsTo('service', Service::class); } } diff --git a/library/Icingadb/Model/DowntimeHistory.php b/library/Icingadb/Model/DowntimeHistory.php index fc65707f..24b23c50 100644 --- a/library/Icingadb/Model/DowntimeHistory.php +++ b/library/Icingadb/Model/DowntimeHistory.php @@ -68,7 +68,7 @@ class DowntimeHistory extends Model // @TODO(el): Add relation for triggered_by_id $relations->belongsTo('endpoint', Endpoint::class); $relations->belongsTo('environment', Environment::class); - $relations->belongsTo('host', Host::class)->setJoinType('LEFT'); - $relations->belongsTo('service', Service::class)->setJoinType('LEFT'); + $relations->belongsTo('host', Host::class); + $relations->belongsTo('service', Service::class); } } diff --git a/library/Icingadb/Model/History.php b/library/Icingadb/Model/History.php index e704c814..dd10be03 100644 --- a/library/Icingadb/Model/History.php +++ b/library/Icingadb/Model/History.php @@ -59,8 +59,8 @@ class History extends Model // @TODO(el): Add relation for flapping_history_id $relations->belongsTo('endpoint', Endpoint::class); $relations->belongsTo('environment', Environment::class); - $relations->belongsTo('host', Host::class)->setJoinType('LEFT'); - $relations->belongsTo('service', Service::class)->setJoinType('LEFT'); + $relations->belongsTo('host', Host::class); + $relations->belongsTo('service', Service::class); $relations->belongsTo('comment', CommentHistory::class) ->setCandidateKey('comment_history_id') ->setForeignKey('comment_id') diff --git a/library/Icingadb/Model/NotificationHistory.php b/library/Icingadb/Model/NotificationHistory.php index 169399c0..96462646 100644 --- a/library/Icingadb/Model/NotificationHistory.php +++ b/library/Icingadb/Model/NotificationHistory.php @@ -58,7 +58,7 @@ class NotificationHistory extends Model public function createRelations(Relations $relations) { $relations->belongsTo('environment', Environment::class); - $relations->belongsTo('host', Host::class)->setJoinType('LEFT'); - $relations->belongsTo('service', Service::class)->setJoinType('LEFT'); + $relations->belongsTo('host', Host::class); + $relations->belongsTo('service', Service::class); } } diff --git a/library/Icingadb/Model/StateHistory.php b/library/Icingadb/Model/StateHistory.php index 5fb409be..9d1293b3 100644 --- a/library/Icingadb/Model/StateHistory.php +++ b/library/Icingadb/Model/StateHistory.php @@ -52,7 +52,7 @@ class StateHistory extends Model { $relations->belongsTo('endpoint', Endpoint::class); $relations->belongsTo('environment', Environment::class); - $relations->belongsTo('host', Host::class)->setJoinType('LEFT'); - $relations->belongsTo('service', Service::class)->setJoinType('LEFT'); + $relations->belongsTo('host', Host::class); + $relations->belongsTo('service', Service::class); } }