mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 04:07:27 +00:00
FIX: properly order pinned topics
This commit is contained in:
parent
880dcbb365
commit
74e8ca2a4f
@ -5,16 +5,10 @@ module TopicQuerySQL
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
# use the constants in conjuction with COALESCE to determine the order with regard to pinned
|
|
||||||
# topics that have been cleared by the user. There might be a cleaner way to do this.
|
|
||||||
def lowest_date
|
def lowest_date
|
||||||
"2010-01-01"
|
"2010-01-01"
|
||||||
end
|
end
|
||||||
|
|
||||||
def highest_date
|
|
||||||
"infinity"
|
|
||||||
end
|
|
||||||
|
|
||||||
def order_by_category_sql(dir)
|
def order_by_category_sql(dir)
|
||||||
"CASE WHEN categories.id = #{SiteSetting.uncategorized_category_id.to_i} THEN '' ELSE categories.name END #{dir}"
|
"CASE WHEN categories.id = #{SiteSetting.uncategorized_category_id.to_i} THEN '' ELSE categories.name END #{dir}"
|
||||||
end
|
end
|
||||||
@ -23,17 +17,18 @@ module TopicQuerySQL
|
|||||||
def order_with_pinned_sql
|
def order_with_pinned_sql
|
||||||
"CASE
|
"CASE
|
||||||
WHEN (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
|
WHEN (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
|
||||||
THEN '#{highest_date}'
|
THEN topics.pinned_at + interval '9999 years'
|
||||||
ELSE topics.bumped_at
|
ELSE topics.bumped_at
|
||||||
END DESC"
|
END DESC"
|
||||||
end
|
end
|
||||||
|
|
||||||
# If you've clearned the pin, use bumped_at, otherwise put it at the top
|
# If you've clearned the pin, use bumped_at, otherwise put it at the top
|
||||||
def order_nocategory_with_pinned_sql
|
def order_nocategory_with_pinned_sql
|
||||||
"CASE
|
"CASE
|
||||||
WHEN topics.pinned_globally and (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
|
WHEN topics.pinned_globally
|
||||||
THEN '#{highest_date}'
|
AND (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
|
||||||
ELSE topics.bumped_at
|
THEN topics.pinned_at + interval '9999 years'
|
||||||
|
ELSE topics.bumped_at
|
||||||
END DESC"
|
END DESC"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -42,7 +37,7 @@ module TopicQuerySQL
|
|||||||
end
|
end
|
||||||
|
|
||||||
def order_nocategory_basic_bumped
|
def order_nocategory_basic_bumped
|
||||||
"CASE WHEN topics.pinned_globally and (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC"
|
"CASE WHEN topics.pinned_globally AND (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC"
|
||||||
end
|
end
|
||||||
|
|
||||||
def order_top_for(score)
|
def order_top_for(score)
|
||||||
@ -51,7 +46,7 @@ module TopicQuerySQL
|
|||||||
|
|
||||||
def order_top_with_pinned_category_for(score)
|
def order_top_with_pinned_category_for(score)
|
||||||
# display pinned topics first
|
# display pinned topics first
|
||||||
"CASE WHEN COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}') THEN 1 ELSE 0 END DESC,
|
"CASE WHEN (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}')) THEN 0 ELSE 1 END,
|
||||||
top_topics.#{score} DESC,
|
top_topics.#{score} DESC,
|
||||||
topics.bumped_at DESC"
|
topics.bumped_at DESC"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user