Bug
cerber_traffic only has KEY stamp (stamp). No index on ip.
cerber_log only has KEY ip (ip). No index on stamp.
Any query filtering by ip + stamp (geo updates, bot checks, lockout counts) does a full table scan. On active sites these tables grow to 3 GB+, causing queries to take 30–50 seconds each. They queue up, exhaust all MySQL connections, and crash the site with “Error establishing database connection”.
Observed on production: 108 concurrent PHP processes stuck on UPDATE cerber_traffic SET country = '...' WHERE ip = '...' AND country = '' — all doing full table scans.
Fix
Add these indexes in cerber_upgrade_db():
-- cerber_traffic: covers ip + time range queries (geo, bot checks)
ALTER TABLE cerber_traffic ADD INDEX idx_ip_stamp (ip, stamp);
-- cerber_traffic: covers cleanup DELETE by user_id + stamp
ALTER TABLE cerber_traffic ADD INDEX idx_user_stamp (user_id, stamp);
-- cerber_log: replace single KEY ip with composite (covers ip + time queries)
ALTER TABLE cerber_log DROP INDEX ip;
ALTER TABLE cerber_log ADD INDEX idx_ip_stamp (ip, stamp);
-- cerber_log: for dashboard/report queries filtering by time range
ALTER TABLE cerber_log ADD INDEX idx_stamp (stamp);
-- cerber_log: for activity + time range queries (lockout/login counts)
ALTER TABLE cerber_log ADD INDEX idx_activity_stamp (activity, stamp);
Safe for auto-cleanup - MySQL maintains indexes automatically on INSERT/DELETE.