Skip to content

Commit 5f34a62

Browse files
committed
Revert "Merge pull request discourse#1896 from nickborromeo/category-list"
1 parent 085f799 commit 5f34a62

File tree

3 files changed

+42
-56
lines changed

3 files changed

+42
-56
lines changed

app/models/category.rb

+2-13
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ class Category < ActiveRecord::Base
6363
scoped_to_permissions(guardian, [:create_post, :full])
6464
end
6565
}
66-
67-
scope :featured_users, ->{ includes(:featured_users) }
68-
6966
delegate :post_template, to: 'self.class'
7067

7168
# permission is just used by serialization
@@ -151,14 +148,6 @@ def self.update_stats
151148
posts_week = (#{posts_week})")
152149
end
153150

154-
def self.ordered_list(guardian)
155-
self.secured(guardian)
156-
.order('position asc')
157-
.order('COALESCE(categories.posts_week, 0) DESC')
158-
.order('COALESCE(categories.posts_month, 0) DESC')
159-
.order('COALESCE(categories.posts_year, 0) DESC')
160-
end
161-
162151
def visible_posts
163152
query = Post.joins(:topic)
164153
.where(['topics.category_id = ?', self.id])
@@ -342,8 +331,8 @@ def self.query_parent_category(parent_slug)
342331
end
343332

344333
def self.query_category(slug, parent_category_id)
345-
self.where(slug: slug, parent_category_id: parent_category_id).featured_users.first ||
346-
self.where(id: slug.to_i, parent_category_id: parent_category_id).featured_users.first
334+
self.where(slug: slug, parent_category_id: parent_category_id).includes(:featured_users).first ||
335+
self.where(id: slug.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
347336
end
348337

349338
def self.find_by_email(email)

app/models/category_list.rb

+39-43
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,16 @@ def latest_posts_count
3535

3636
# Retrieve a list of all the topics we'll need
3737
def find_relevant_topics
38-
@topics_by_id = {}
3938
@topics_by_category_id = {}
4039
category_featured_topics = CategoryFeaturedTopic.select([:category_id, :topic_id]).order(:rank)
40+
@topics_by_id = {}
4141

42-
build_topics_by_id(category_featured_topics)
43-
build_topics_by_category_id(category_featured_topics)
44-
end
45-
46-
def build_topics_by_id(category_featured_topics)
4742
@all_topics = Topic.where(id: category_featured_topics.map(&:topic_id))
4843
@all_topics.each do |t|
4944
t.include_last_poster = true if include_latest_posts? # hint for serialization
5045
@topics_by_id[t.id] = t
5146
end
52-
end
5347

54-
def build_topics_by_category_id(category_featured_topics)
5548
category_featured_topics.each do |cft|
5649
@topics_by_category_id[cft.category_id] ||= []
5750
@topics_by_category_id[cft.category_id] << cft.topic_id
@@ -60,63 +53,66 @@ def build_topics_by_category_id(category_featured_topics)
6053

6154
# Find a list of all categories to associate the topics with
6255
def find_categories
63-
@categories = Category.featured_users.ordered_list(@guardian).to_a
64-
subcategories = {}
65-
to_delete = Set.new
56+
@categories = Category
57+
.includes(:featured_users, subcategories: [:topic_only_relative_url])
58+
.secured(@guardian)
59+
.order('position asc')
60+
.order('COALESCE(categories.posts_week, 0) DESC')
61+
.order('COALESCE(categories.posts_month, 0) DESC')
62+
.order('COALESCE(categories.posts_year, 0) DESC')
63+
.to_a
6664

6765
if latest_post_only?
6866
@categories = @categories.includes(:latest_post => {:topic => :last_poster} )
6967
end
7068

71-
build_subcategories
72-
73-
if subcategories.present?
74-
@categories.each { |c| c.subcategory_ids = subcategories[c.id] }
75-
@categories.delete_if {|c| to_delete.include?(c) }
76-
end
77-
78-
set_all_topics if latest_post_only?
79-
set_displayable_category_topics if @topics_by_category_id
80-
end
81-
82-
def build_subcategories
69+
subcategories = {}
70+
to_delete = Set.new
8371
@categories.each do |c|
8472
if c.parent_category_id.present?
8573
subcategories[c.parent_category_id] ||= []
8674
subcategories[c.parent_category_id] << c.id
8775
to_delete << c
8876
end
8977
end
90-
end
9178

92-
def set_all_topics
93-
@all_topics = []
94-
@categories.each do |c|
95-
if c.latest_post && c.latest_post.topic
96-
c.displayable_topics = [c.latest_post.topic]
97-
topic = c.latest_post.topic
98-
topic.include_last_poster = true # hint for serialization
99-
@all_topics << topic
79+
if subcategories.present?
80+
@categories.each do |c|
81+
c.subcategory_ids = subcategories[c.id]
10082
end
83+
@categories.delete_if {|c| to_delete.include?(c) }
10184
end
102-
end
10385

104-
def set_displayable_category_topics
105-
@categories.each do |c|
106-
topics_in_cat = @topics_by_category_id[c.id]
107-
if topics_in_cat.present?
108-
c.displayable_topics = []
109-
topics_in_cat.each do |topic_id|
110-
topic = @topics_by_id[topic_id]
111-
if topic.present?
112-
topic.category = c
113-
c.displayable_topics << topic
86+
if latest_post_only?
87+
@all_topics = []
88+
@categories.each do |c|
89+
if c.latest_post && c.latest_post.topic
90+
c.displayable_topics = [c.latest_post.topic]
91+
topic = c.latest_post.topic
92+
topic.include_last_poster = true # hint for serialization
93+
@all_topics << topic
94+
end
95+
end
96+
end
97+
98+
if @topics_by_category_id
99+
@categories.each do |c|
100+
topics_in_cat = @topics_by_category_id[c.id]
101+
if topics_in_cat.present?
102+
c.displayable_topics = []
103+
topics_in_cat.each do |topic_id|
104+
topic = @topics_by_id[topic_id]
105+
if topic.present?
106+
topic.category = c
107+
c.displayable_topics << topic
108+
end
114109
end
115110
end
116111
end
117112
end
118113
end
119114

115+
120116
# Remove any empty categories unless we can create them (so we can see the controls)
121117
def prune_empty
122118
if !@guardian.can_create?(Category)

docs/INSTALL-ubuntu.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Install RVM
125125
# As 'discourse'
126126
# Install RVM
127127
\curl -s -S -L https://get.rvm.io | bash -s stable
128+
128129
# Refresh your profile
129130
. ~/.rvm/scripts/rvm
130131

0 commit comments

Comments
 (0)