mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
OPTIMIZATION: Add index to post_timings
and adjust the query
This commit is contained in:
parent
b414a3590a
commit
09d7a697bf
2 changed files with 8 additions and 4 deletions
|
@ -30,10 +30,9 @@ class UserStat < ActiveRecord::Base
|
||||||
FROM
|
FROM
|
||||||
(SELECT pt.user_id,
|
(SELECT pt.user_id,
|
||||||
COUNT(*) AS c
|
COUNT(*) AS c
|
||||||
FROM post_timings AS pt
|
FROM users AS u
|
||||||
WHERE pt.user_id IN (
|
INNER JOIN post_timings AS pt ON pt.user_id = u.id
|
||||||
SELECT u1.id FROM users u1 where u1.last_seen_at > :seen_at
|
WHERE u.last_seen_at > :seen_at
|
||||||
)
|
|
||||||
GROUP BY pt.user_id) AS X
|
GROUP BY pt.user_id) AS X
|
||||||
WHERE X.user_id = user_stats.user_id AND
|
WHERE X.user_id = user_stats.user_id AND
|
||||||
X.c <> posts_read_count
|
X.c <> posts_read_count
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class CreatePostTimingsUserIndex < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_index :post_timings, :user_id
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue