mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 22:13:45 +08:00
Revert "Merge pull request #1896 from nickborromeo/category-list"
This commit is contained in:
parent
085f7997a2
commit
5f34a621b5
|
@ -63,9 +63,6 @@ class Category < ActiveRecord::Base
|
|||
scoped_to_permissions(guardian, [:create_post, :full])
|
||||
end
|
||||
}
|
||||
|
||||
scope :featured_users, ->{ includes(:featured_users) }
|
||||
|
||||
delegate :post_template, to: 'self.class'
|
||||
|
||||
# permission is just used by serialization
|
||||
|
@ -151,14 +148,6 @@ SQL
|
|||
posts_week = (#{posts_week})")
|
||||
end
|
||||
|
||||
def self.ordered_list(guardian)
|
||||
self.secured(guardian)
|
||||
.order('position asc')
|
||||
.order('COALESCE(categories.posts_week, 0) DESC')
|
||||
.order('COALESCE(categories.posts_month, 0) DESC')
|
||||
.order('COALESCE(categories.posts_year, 0) DESC')
|
||||
end
|
||||
|
||||
def visible_posts
|
||||
query = Post.joins(:topic)
|
||||
.where(['topics.category_id = ?', self.id])
|
||||
|
@ -342,8 +331,8 @@ SQL
|
|||
end
|
||||
|
||||
def self.query_category(slug, parent_category_id)
|
||||
self.where(slug: slug, parent_category_id: parent_category_id).featured_users.first ||
|
||||
self.where(id: slug.to_i, parent_category_id: parent_category_id).featured_users.first
|
||||
self.where(slug: slug, parent_category_id: parent_category_id).includes(:featured_users).first ||
|
||||
self.where(id: slug.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
|
||||
end
|
||||
|
||||
def self.find_by_email(email)
|
||||
|
|
|
@ -35,23 +35,16 @@ class CategoryList
|
|||
|
||||
# Retrieve a list of all the topics we'll need
|
||||
def find_relevant_topics
|
||||
@topics_by_id = {}
|
||||
@topics_by_category_id = {}
|
||||
category_featured_topics = CategoryFeaturedTopic.select([:category_id, :topic_id]).order(:rank)
|
||||
@topics_by_id = {}
|
||||
|
||||
build_topics_by_id(category_featured_topics)
|
||||
build_topics_by_category_id(category_featured_topics)
|
||||
end
|
||||
|
||||
def build_topics_by_id(category_featured_topics)
|
||||
@all_topics = Topic.where(id: category_featured_topics.map(&:topic_id))
|
||||
@all_topics.each do |t|
|
||||
t.include_last_poster = true if include_latest_posts? # hint for serialization
|
||||
@topics_by_id[t.id] = t
|
||||
end
|
||||
end
|
||||
|
||||
def build_topics_by_category_id(category_featured_topics)
|
||||
category_featured_topics.each do |cft|
|
||||
@topics_by_category_id[cft.category_id] ||= []
|
||||
@topics_by_category_id[cft.category_id] << cft.topic_id
|
||||
|
@ -60,26 +53,21 @@ class CategoryList
|
|||
|
||||
# Find a list of all categories to associate the topics with
|
||||
def find_categories
|
||||
@categories = Category.featured_users.ordered_list(@guardian).to_a
|
||||
subcategories = {}
|
||||
to_delete = Set.new
|
||||
@categories = Category
|
||||
.includes(:featured_users, subcategories: [:topic_only_relative_url])
|
||||
.secured(@guardian)
|
||||
.order('position asc')
|
||||
.order('COALESCE(categories.posts_week, 0) DESC')
|
||||
.order('COALESCE(categories.posts_month, 0) DESC')
|
||||
.order('COALESCE(categories.posts_year, 0) DESC')
|
||||
.to_a
|
||||
|
||||
if latest_post_only?
|
||||
@categories = @categories.includes(:latest_post => {:topic => :last_poster} )
|
||||
end
|
||||
|
||||
build_subcategories
|
||||
|
||||
if subcategories.present?
|
||||
@categories.each { |c| c.subcategory_ids = subcategories[c.id] }
|
||||
@categories.delete_if {|c| to_delete.include?(c) }
|
||||
end
|
||||
|
||||
set_all_topics if latest_post_only?
|
||||
set_displayable_category_topics if @topics_by_category_id
|
||||
end
|
||||
|
||||
def build_subcategories
|
||||
subcategories = {}
|
||||
to_delete = Set.new
|
||||
@categories.each do |c|
|
||||
if c.parent_category_id.present?
|
||||
subcategories[c.parent_category_id] ||= []
|
||||
|
@ -87,36 +75,44 @@ class CategoryList
|
|||
to_delete << c
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_all_topics
|
||||
@all_topics = []
|
||||
@categories.each do |c|
|
||||
if c.latest_post && c.latest_post.topic
|
||||
c.displayable_topics = [c.latest_post.topic]
|
||||
topic = c.latest_post.topic
|
||||
topic.include_last_poster = true # hint for serialization
|
||||
@all_topics << topic
|
||||
if subcategories.present?
|
||||
@categories.each do |c|
|
||||
c.subcategory_ids = subcategories[c.id]
|
||||
end
|
||||
@categories.delete_if {|c| to_delete.include?(c) }
|
||||
end
|
||||
|
||||
if latest_post_only?
|
||||
@all_topics = []
|
||||
@categories.each do |c|
|
||||
if c.latest_post && c.latest_post.topic
|
||||
c.displayable_topics = [c.latest_post.topic]
|
||||
topic = c.latest_post.topic
|
||||
topic.include_last_poster = true # hint for serialization
|
||||
@all_topics << topic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_displayable_category_topics
|
||||
@categories.each do |c|
|
||||
topics_in_cat = @topics_by_category_id[c.id]
|
||||
if topics_in_cat.present?
|
||||
c.displayable_topics = []
|
||||
topics_in_cat.each do |topic_id|
|
||||
topic = @topics_by_id[topic_id]
|
||||
if topic.present?
|
||||
topic.category = c
|
||||
c.displayable_topics << topic
|
||||
if @topics_by_category_id
|
||||
@categories.each do |c|
|
||||
topics_in_cat = @topics_by_category_id[c.id]
|
||||
if topics_in_cat.present?
|
||||
c.displayable_topics = []
|
||||
topics_in_cat.each do |topic_id|
|
||||
topic = @topics_by_id[topic_id]
|
||||
if topic.present?
|
||||
topic.category = c
|
||||
c.displayable_topics << topic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Remove any empty categories unless we can create them (so we can see the controls)
|
||||
def prune_empty
|
||||
if !@guardian.can_create?(Category)
|
||||
|
|
|
@ -125,6 +125,7 @@ Install RVM
|
|||
# As 'discourse'
|
||||
# Install RVM
|
||||
\curl -s -S -L https://get.rvm.io | bash -s stable
|
||||
|
||||
# Refresh your profile
|
||||
. ~/.rvm/scripts/rvm
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user