mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-11-15 01:11:23 +00:00
Rewrite recent_topic sql to return unique topics on subquery
This commit is contained in:
parent
fbf82b6948
commit
e0eaa89fbf
2 changed files with 6 additions and 5 deletions
|
@ -43,11 +43,12 @@ class Topic < ActiveRecord::Base
|
|||
|
||||
def self.recent_topics
|
||||
find_by_sql %q{
|
||||
SELECT DISTINCT topics.*
|
||||
FROM (SELECT id, topic_id
|
||||
SELECT topics.*
|
||||
FROM (SELECT max(id) as max_id, topic_id
|
||||
FROM posts
|
||||
ORDER BY id DESC
|
||||
LIMIT 20) AS T
|
||||
GROUP BY topic_id
|
||||
ORDER BY max_id DESC
|
||||
LIMIT 10) AS T
|
||||
INNER JOIN topics
|
||||
ON T.topic_id = topics.id
|
||||
INNER JOIN forums
|
||||
|
|
|
@ -31,7 +31,7 @@ describe Topic do
|
|||
describe ".recent_topics" do
|
||||
it "returns 5 unique, most recently posted topics" do
|
||||
topics = []
|
||||
6.times do
|
||||
10.times do
|
||||
topic = create :topic
|
||||
topics << topic
|
||||
3.times { create :post, topic: topic }
|
||||
|
|
Loading…
Reference in a new issue