Skip to content

A platform for community discussion. Free, open, simple.

FIX: Break ties in Rewind rankings

Régis Hanolb69627d749b1
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/ai_usage.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/ai_usage.rb
index 5689c3e39b6..1e0cef43d18 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/ai_usage.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/ai_usage.rb
@@ -60,7 +60,7 @@ module DiscourseRewind
feature_usage =
base_query
.group(:feature_name)
- .order("SUM(usage_count) DESC")
+ .order("SUM(usage_count) DESC", :feature_name)
.limit(5)
.pluck(:feature_name, Arel.sql("SUM(usage_count)"))
.to_h
@@ -70,7 +70,7 @@ module DiscourseRewind
base_query
.where.not(language_model: nil)
.group(:language_model)
- .order("SUM(usage_count) DESC")
+ .order("SUM(usage_count) DESC", :language_model)
.limit(5)
.pluck(:language_model, Arel.sql("SUM(usage_count)"))
.to_h
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/best_topics.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/best_topics.rb
index bd5879227ff..85f16cfecbe 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/best_topics.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/best_topics.rb
@@ -38,7 +38,7 @@ module DiscourseRewind
.where(topic: { deleted_at: nil, created_at: date, user_id: user.id, visible: true })
.where.not(topic: { archetype: Archetype.private_message })
.where("NOT categories.read_restricted")
- .order("yearly_score DESC NULLS LAST")
+ .order("yearly_score DESC NULLS LAST, top_topics.topic_id")
.limit(3)
.pluck(:topic_id, :title, :excerpt, :yearly_score)
.map do |topic_id, title, excerpt, yearly_score|
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb
index fd521444d40..88fef2790b5 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb
@@ -44,9 +44,9 @@ module DiscourseRewind
.where(chat_channels: { type: "CategoryChannel" })
.where(categories: { read_restricted: false })
.group("chat_channels.id", "chat_channels.slug")
+ .order("COUNT(*) DESC", "chat_channels.id")
+ .limit(5)
.count
- .sort_by { |_, count| -count }
- .first(5)
.map do |(id, slug), count|
{ channel_id: id, channel_slug: slug, message_count: count }
end
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_categories.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_categories.rb
index ed7de4bde15..0af5c49b738 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_categories.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_categories.rb
@@ -29,7 +29,7 @@ module DiscourseRewind
},
)
.group("categories.id, categories.name")
- .order("COUNT(*) DESC")
+ .order("COUNT(*) DESC, categories.id")
.limit(4)
.pluck("categories.id, categories.name")
.map { |category_id, name| { category_id: category_id, name: name } }
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_tags.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_tags.rb
index aec319a357d..f50e0459fda 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_tags.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/most_viewed_tags.rb
@@ -25,7 +25,7 @@ module DiscourseRewind
.joins("INNER JOIN tags ON tags.id = topic_tags.tag_id")
.where(user: user, viewed_at: date, tags: { id: Tag.visible(Guardian.new).pluck(:id) })
.group("tags.id, tags.name, tags.slug")
- .order("COUNT(DISTINCT topic_views.topic_id) DESC")
+ .order("COUNT(DISTINCT topic_views.topic_id) DESC, tags.id")
.limit(4)
.pluck("tags.id, tags.slug, tags.name")
.map { |tag_id, slug, name| { tag_id: tag_id, slug: slug, name: name } }