mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 18:03:38 +08:00
OPTIMIZATION: Add index to post_timings
and adjust the query
This commit is contained in:
parent
b414a3590a
commit
09d7a697bf
|
@ -30,10 +30,9 @@ class UserStat < ActiveRecord::Base
|
|||
FROM
|
||||
(SELECT pt.user_id,
|
||||
COUNT(*) AS c
|
||||
FROM post_timings AS pt
|
||||
WHERE pt.user_id IN (
|
||||
SELECT u1.id FROM users u1 where u1.last_seen_at > :seen_at
|
||||
)
|
||||
FROM users AS u
|
||||
INNER JOIN post_timings AS pt ON pt.user_id = u.id
|
||||
WHERE u.last_seen_at > :seen_at
|
||||
GROUP BY pt.user_id) AS X
|
||||
WHERE X.user_id = user_stats.user_id AND
|
||||
X.c <> posts_read_count
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class CreatePostTimingsUserIndex < ActiveRecord::Migration
|
||||
def change
|
||||
add_index :post_timings, :user_id
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user