Remove triggers views instead#4571
Open
BHMSD-bdailey wants to merge 2 commits intoZoneMinder:masterfrom
Open
Conversation
…s with views Remove denormalized event summary tables and their associated triggers, replacing them with views that query the Events table directly. This eliminates trigger maintenance overhead and periodic reconciliation in zmaudit/zmstats, since the views compute stats on the fly. - Remove trigger definitions for event summary table maintenance - Remove event summary table inserts from zm_event.cpp - Remove event count reconciliation queries from zmaudit.pl - Remove DELETE-on-views calls from zmstats.pl (views filter by date inherently) - Remove Event_Summaries DELETE from Monitor.php (can't delete from a view) - Add db/views.sql with view definitions and covering index - Add upgrade script zm_update-1.37.78.sql.in (drop triggers, drop tables, create views) - Update zm_create.sql.in to use views instead of tables for fresh installs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace the Event_Summaries view with a physical snapshot table refreshed via Stale-While-Revalidate (SWR) pattern. A stored procedure (Refresh_Summaries_SWR) uses GET_LOCK for non-blocking concurrency and atomic table rename for zero-downtime refresh. Database changes (db/views.sql): - Rename Event_Summaries view to VIEW_Event_Summaries (source view) - Add Event_Summaries snapshot table and Event_Summaries_Metadata table - Add Refresh_Summaries_SWR stored procedure with GET_LOCK and atomic rename pattern to prevent thundering herd - Add MySQL EVENT for background refresh every 600 seconds PHP call sites (web/): - Add ensureSummariesFresh() helper in database.php with static per-request dedup and 60s staleness check - Call ensureSummariesFresh() before Event_Summaries queries in console.php, _monitor_filters.php, and Monitor.php - Add beforeFind() hook in CakePHP Event_Summary model Perl call sites (scripts/): - Add ensureSummariesFresh() sub in Event_Summary.pm with per-process 60s rate-limiting - Call ensureSummariesFresh() in Monitor.pm Event_Summary accessor Upgrade path (db/zm_update-1.37.78.sql.in): - Drop any prior Event_Summaries view or table before recreating Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.