# If you've clearned the pin, use bumped_at, otherwise put it at the top
deforder_nocategory_with_pinned_sql
"CASE
WHENtopics.category_id=#{SiteSetting.uncategorized_category_id.to_i} and (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
THEN'#{highest_date}'
ELSEtopics.bumped_at
ENDDESC"
end
# For anonymous users
deforder_nocategory_basic_bumped
"CASE WHEN topics.category_id = #{SiteSetting.uncategorized_category_id.to_i} and (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC"
end
deforder_basic_bumped
"CASE WHEN (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC"