diff options
author | Vitaly Takmazov | 2018-04-15 22:48:32 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-04-15 22:48:32 +0300 |
commit | 4bcb69153187f73d5a981db4a9c403622768af1b (patch) | |
tree | d65828b32c6917c908fa3399dd3ab138160dd609 | |
parent | 0aa64b3201df580918ba496e3df65f0b7dfdd41f (diff) |
add script for lastmessage update
-rw-r--r-- | contrib/scripts/update_lastmessage.sql | 1 |
1 files changed, 1 insertions, 0 deletions
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; |