From 4bcb69153187f73d5a981db4a9c403622768af1b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 15 Apr 2018 22:48:32 +0300 Subject: add script for lastmessage update --- contrib/scripts/update_lastmessage.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 contrib/scripts/update_lastmessage.sql (limited to 'contrib') diff --git a/contrib/scripts/update_lastmessage.sql b/contrib/scripts/update_lastmessage.sql new file mode 100644 index 00000000..3a843408 --- /dev/null +++ b/contrib/scripts/update_lastmessage.sql @@ -0,0 +1 @@ +UPDATE users, (SELECT users.`id` uid, MAX(COALESCE(replies.ts, messages.ts)) lastt FROM messages LEFT JOIN replies ON messages.`message_id`=replies.`message_id` LEFT JOIN users ON users.id=messages.user_id GROUP BY users.`id`) res SET users.lastmessage = res.lastt WHERE users.`id` = res.uid; -- cgit v1.2.3