perf: add occurred_at indexes to connections
Time-window queries (dashboard stats, recent connections, JSON API, purge) had no usable index and full-scanned the connections table on every load, so the dashboard slowed down as data accumulated. - Add idx_occurred (occurred_at) for counts, MAX, ORDER BY ... LIMIT, and the purge delete - Add idx_src_ip_occ (src_ip, occurred_at) so frequent_ips() runs as a covering index scan - Drop the now-redundant standalone idx_src_ip Migrations in setup.php are idempotent (information_schema checks) and portable across MySQL 8 and MariaDB.
This commit is contained in:
1 parent
05e9fbe76e
commit
849360e61c
3 files changed
+41
-3
No files matched your search
+2
-1
@@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS connections (
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_node_occurred (node_id, occurred_at),
|
||||
KEY idx_src_ip (src_ip),
|
||||
KEY idx_occurred (occurred_at),
|
||||
KEY idx_src_ip_occ (src_ip, occurred_at),
|
||||
KEY idx_dst_port (dst_port),
|
||||
CONSTRAINT fk_conn_node FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
Reference in new issue
Block a user