mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
Merge pull request #5719 from AJ0070/console-n1
perf: batch console still-thumbnail events and throttle session timestamp writes
This commit is contained in:
2 files changed
+30
-8
No files matched your search
+21
-7
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user