Unverified Commit 663acfcf authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #930 from jacklul/fix_message_cleanup

Possible fix for #917
parents 0f8e0275 82f3b635
...@@ -10,6 +10,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -10,6 +10,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Botan.io service has been discontinued. - Botan.io service has been discontinued.
### Removed ### Removed
### Fixed ### Fixed
- Constraint errors in `/cleanup` command.
### Security ### Security
## [0.55.1] - 2019-01-06 ## [0.55.1] - 2019-01-06
......
...@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand ...@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand
SELECT `id` SELECT `id`
FROM `%4$s` FROM `%4$s`
WHERE `chat_id` = `%4$s`.`id` WHERE `chat_id` = `%4$s`.`id`
AND `updated_at` < \'%1$s\'
) )
AND ( AND (
`message_id` IS NOT NULL `message_id` IS NOT NULL
...@@ -301,20 +302,38 @@ class CleanupCommand extends AdminCommand ...@@ -301,20 +302,38 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) { if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf( $queries[] = sprintf(
'DELETE FROM `%1$s` 'DELETE FROM `%1$s`
WHERE `date` < \'%2$s\' WHERE id IN (
AND `id` NOT IN ( SELECT id
SELECT `message_id` FROM (
FROM `%3$s` SELECT id
WHERE `message_id` = `%1$s`.`id` FROM `message`
) WHERE `date` < \'%2$s\'
AND `id` NOT IN ( AND `id` NOT IN (
SELECT `message_id` SELECT `message_id`
FROM `%4$s` FROM `%3$s`
WHERE `message_id` = `%1$s`.`id` WHERE `message_id` = `%1$s`.`id`
) )
AND `id` NOT IN (
SELECT `message_id`
FROM `%4$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%5$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT a.`reply_to_message` FROM `%1$s` a
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
)
ORDER BY `id` DESC
) a
)
', ',
TB_MESSAGE, TB_MESSAGE,
$clean_older_than['message'], $clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE, TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY TB_CALLBACK_QUERY
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment