diff --git a/web/ajax/console.php b/web/ajax/console.php index 8ae31e196f..4c5e5b9f92 100644 --- a/web/ajax/console.php +++ b/web/ajax/console.php @@ -304,6 +304,26 @@ function queryRequest() { } } + $still_monitor_ids = array(); + foreach ($filtered_monitors as $monitor) { + if (ZM_WEB_LIST_THUMBS && canView('Stream') && ($monitor['Capturing'] != 'None') + && ($monitor['Analysing'] == 'None') && ($monitor['Decoding'] == 'None')) { + $still_monitor_ids[] = intval($monitor['Id']); + } + } + $still_events_by_monitor_id = array(); + if (count($still_monitor_ids)) { + $placeholders = implode(',', array_fill(0, count($still_monitor_ids), '?')); + $rows = dbFetchAll( + 'SELECT E.* FROM Events E JOIN (SELECT MAX(Id) AS Id FROM Events WHERE EndDateTime IS NOT NULL AND MonitorId IN ('.$placeholders.') GROUP BY MonitorId) L ON L.Id = E.Id', + NULL, + $still_monitor_ids + ); + foreach ($rows as $row) { + $still_events_by_monitor_id[$row['MonitorId']] = new ZM\Event($row); + } + } + // Process each monitor and build row data $footer_totals = array( 'monitor_count' => count($all_filtered_monitors), @@ -518,13 +538,7 @@ function queryRequest() { // (ZM's nph-zms can't produce frames when not decoding) if ($monitor['Analysing'] == 'None' && $monitor['Decoding'] == 'None') { $debugAttr .= ' data-debug-still="event"'; - $event = ZM\Event::find_one( - array( - 'MonitorId' => $monitor['Id'], - 'EndDateTime' => 'NOT NULL' - ), - array('order' => 'Id DESC') - ); + $event = isset($still_events_by_monitor_id[$monitor['Id']]) ? $still_events_by_monitor_id[$monitor['Id']] : null; if ($event) { $stillSrc = $event->getThumbnailSrc(array(), '&'); // Default stream/video sources from event (may be overridden by live streaming below) diff --git a/web/includes/session.php b/web/includes/session.php index 4719fb295b..b49b588297 100644 --- a/web/includes/session.php +++ b/web/includes/session.php @@ -188,6 +188,9 @@ function zm_session_clear() { // without it session.use_strict_mode has no effect for a user handler, and an // id the client made up became its session id. class ZMSessionHandler implements SessionHandlerInterface, SessionUpdateTimestampHandlerInterface { + // Access time of the stored row read() found, and the id it belongs to. + private $readId = null; + private $readAccess = null; public function open($path, $name): bool { return zmDbConnOrNull() ? true : false; } @@ -198,7 +201,7 @@ class ZMSessionHandler implements SessionHandlerInterface, SessionUpdateTimestam #[\ReturnTypeWillChange] public function read($id){ if (!($db = zmDbConnOrNull())) return ''; - $sth = $db->prepare('SELECT data FROM Sessions WHERE id = :id'); + $sth = $db->prepare('SELECT data, access FROM Sessions WHERE id = :id'); if (!$sth->bindParam(':id', $id, PDO::PARAM_STR, 32)) { ZM\Error("Failed to bind param"); if (!$sth->bindParam(':id', $id, PDO::PARAM_STR)) { @@ -208,6 +211,8 @@ class ZMSessionHandler implements SessionHandlerInterface, SessionUpdateTimestam if ( $sth->execute() ) { if (( $row = $sth->fetch(PDO::FETCH_ASSOC) ) ) { + $this->readId = $id; + $this->readAccess = intval($row['access']); return $row['data']; } } @@ -268,6 +273,9 @@ class ZMSessionHandler implements SessionHandlerInterface, SessionUpdateTimestam } // Called instead of write() when the session data didn't change. public function updateTimestamp($id, $data) : bool { + if (($this->readId === $id) && ($this->readAccess !== null) && ((time() - $this->readAccess) < 60)) { + return true; + } return $this->write($id, $data); } } # end class Session