mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-10-06 09:22:04 -04:00
Every query on Frames filters on EventId and orders or ranges by FrameId, and nothing needs a frame by Id. The Id primary key was a clustered index nothing read, and EventId_FrameId_idx was a secondary index every query used. On a copy of a local table that secondary index was half the table's size. With (EventId, FrameId) as the primary key the index is gone, and an event's rows are stored together, so deleting an event is a range delete. zm_update-1.39.36.sql: - converts AI_Detections.FrameId from Frames.Id to the per-event frame number, drops its foreign key to Frames and indexes (EventId, FrameId). A composite foreign key cannot replace it: ON DELETE SET NULL would have to null the NOT NULL EventId, and Frames rows are written in batches, so a detection can be recorded before its frame row. - removes duplicate (EventId, FrameId) rows, keeping the earliest. - rebuilds Frames with the new primary key. - removes ON UPDATE CURRENT_TIMESTAMP from Frames.TimeStamp. Any UPDATE of a frame row was overwriting its capture time. Each step checks the current schema first, so the migration can be re-run. REST API: view, edit and delete take /frames/<action>/<EventId>/<FrameId>.json. The old single-Id URLs return 404. CakePHP 2 has no composite keys, so the model's primaryKey is EventId. That keeps Event's dependent cascade delete limited to the event's own frames. The controller writes with explicit (EventId, FrameId) conditions instead of save(), which would match rows on EventId alone. Edit no longer changes EventId or FrameId. view=image with fid but no eid used to look up Frames.Id. It now returns 404. The Perl Frame class is identified by (EventId, FrameId). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
namespace ZM;
|
|
require_once('database.php');
|
|
require_once('Event.php');
|
|
require_once('Object.php');
|
|
|
|
class Frame extends ZM_Object {
|
|
protected static $table = 'Frames';
|
|
protected $defaults = array(
|
|
'EventId' => 0,
|
|
'FrameId' => 0,
|
|
'Type' => 'Normal',
|
|
'TimeStamp' => 0,
|
|
'Delta' => 0.00,
|
|
'Score' => 0,
|
|
);
|
|
|
|
public static function find( $parameters = array(), $options = array() ) {
|
|
return ZM_Object::_find(self::class, $parameters, $options);
|
|
}
|
|
|
|
public static function find_one( $parameters = array(), $options = array() ) {
|
|
return ZM_Object::_find_one(self::class, $parameters, $options);
|
|
}
|
|
|
|
public function Storage() {
|
|
return $this->Event()->Storage();
|
|
}
|
|
|
|
public function Event() {
|
|
return new Event( $this->{'EventId'} );
|
|
}
|
|
|
|
public function getImageSrc( $show='capture' ) {
|
|
return '?view=image&fid='.$this->{'FrameId'}.'&eid='.$this->{'EventId'}.'&show='.$show;
|
|
#return '?view=image&fid='.$this->{'Id'}.'&show='.$show.'&filename='.$this->Event()->MonitorId().'_'.$this->{'EventId'}.'_'.$this->{'FrameId'}.'.jpg';
|
|
} // end function getImageSrc
|
|
|
|
} # end class Frame
|
|
?>
|