mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
[MIRROR] 1664 patch (#11108)
Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1fdda1cc39
commit
5386230d96
@@ -246,7 +246,7 @@ CREATE TABLE IF NOT EXISTS `chatlogs_ckeys` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `chatlogs_logs` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`round_id` int(11) NOT NULL DEFAULT -1,
|
||||
`target` varchar(45) NOT NULL,
|
||||
`text` mediumtext NOT NULL,
|
||||
@@ -257,3 +257,40 @@ CREATE TABLE IF NOT EXISTS `chatlogs_logs` (
|
||||
KEY `chatlogs_ckeys_FK` (`target`),
|
||||
CONSTRAINT `chatlogs_ckeys_FK` FOREIGN KEY (`target`) REFERENCES `chatlogs_ckeys` (`ckey`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE EVENT `chatlogs_logs_clear_old_logs`
|
||||
ON SCHEDULE
|
||||
EVERY 1 MONTH STARTS '2025-01-01 04:00:00'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
COMMENT 'This event periodically clears the chatlog logs of very old logs'
|
||||
DO BEGIN
|
||||
|
||||
DELETE FROM chatlogs_logs WHERE created_at < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 MONTH)) * 1000;
|
||||
|
||||
END
|
||||
|
||||
CREATE TABLE `chatlogs_rounds` (
|
||||
`round_id` BIGINT(20) NOT NULL DEFAULT -1,
|
||||
`ckey` VARCHAR(45) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
|
||||
PRIMARY KEY (`round_id`, `ckey`) USING BTREE
|
||||
) ENGINE=InnoDB COLLATE='utf8mb4_uca1400_ai_ci';
|
||||
|
||||
CREATE PROCEDURE `chatlogs_rounds_insert`(
|
||||
IN `p_round_id` BIGINT,
|
||||
IN `p_ckey` VARCHAR(45)
|
||||
)
|
||||
LANGUAGE SQL
|
||||
NOT DETERMINISTIC
|
||||
CONTAINS SQL
|
||||
SQL SECURITY INVOKER
|
||||
COMMENT 'Inserts a new row into \'chatlogs_rounds\' and deletes the oldest entry, if the ckey already has 10 round id\'s stored.'
|
||||
BEGIN
|
||||
|
||||
INSERT IGNORE INTO chatlogs_rounds(round_id, ckey) VALUES (p_round_id, p_ckey);
|
||||
|
||||
IF (SELECT COUNT(*) FROM chatlogs_rounds WHERE ckey = p_ckey) > 10 THEN
|
||||
DELETE FROM chatlogs_rounds WHERE ckey = p_ckey ORDER BY round_id ASC LIMIT 1;
|
||||
END IF;
|
||||
|
||||
END
|
||||
|
||||
Reference in New Issue
Block a user