From f4b75d4f14db75a1e45bb95ab77ac96d343b8c0a Mon Sep 17 00:00:00 2001 From: jaidhar Date: Wed, 10 Nov 2010 01:32:14 +0000 Subject: [PATCH] XML Plugin: Speed improvement where using inner join on Frames table was causing large delays for huge tables git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3184 e3e1d417-86f3-4887-817a-d78f3d33393f --- web/skins/xml/views/console.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/skins/xml/views/console.php b/web/skins/xml/views/console.php index 6df7005b7..cf3f1c817 100644 --- a/web/skins/xml/views/console.php +++ b/web/skins/xml/views/console.php @@ -198,7 +198,7 @@ foreach( $displayMonitors as $monitor ) $offset = 0; if (isset($_GET['numEvents'])) { $numEvents = $_GET['numEvents']; - $eventsSql = "select E.Id,E.MonitorId,M.Name As MonitorName,E.Name,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived,F.FrameId as MaxFrameId from Monitors as M inner join Events as E on (M.Id = E.MonitorId) and ( E.MonitorId = ".$monitor['Id']." ) inner join Frames as F on (E.Id = F.EventId) and (E.MaxScore = F.Score) and (F.Type = \"Alarm\") group by (E.Id) order by E.StartTime desc"; + $eventsSql = "select E.Id,E.MonitorId,M.Name As MonitorName,E.Name,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived from Monitors as M inner join Events as E on (M.Id = E.MonitorId) and ( E.MonitorId = ".$monitor['Id']." ) order by E.StartTime desc"; $eventsSql .= " limit ".$numEvents; /* If there is an pageOff tag for this monitor, then retrieve the offset. Otherwise, don't specify offset */ if (isset($_GET['pageOff'.$monitor['Id']])) { @@ -230,7 +230,10 @@ foreach( $displayMonitors as $monitor ) xml_tag_val("TOTSCORE", $event['TotScore']); xml_tag_val("AVGSCORE", $event['AvgScore']); xml_tag_val("MAXSCORE", $event['MaxScore']); - xml_tag_val("MAXFRAMEID", $event['MaxFrameId']); + /* Grab the max frame-id from Frames table */ + $framesSql = "select FrameId from Frames where (Type = \"Alarm\") and (EventId = ".$event['Id'].") order by Score desc limit 1"; + $fr = dbFetchOne($framesSql); + xml_tag_val("MAXFRAMEID", $fr['FrameId']); xml_tag_sec("EVENT",0); } }