This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_uncategorized | |
# Support for uncategorized topics | |
uncategorized_topics = Topio.uncategorized_topics # <----- call to Topic | |
if uncategorized_topics.present? | |
totals = Topic.totals # <----- call to Topic | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.uncategorized_topics | |
listable_topics | |
.visible | |
.where(category_id: nil) | |
.topic_list_order | |
.limit(SiteSetting.category_featured_topics) | |
end | |
def self.totals | |
exec_sql("SELECT SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 WEEK') THEN 1 ELSE 0 END) as topics_week, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_uncategorized | |
# Support for uncategorized topics | |
uncategorized_topics = get_uncategorized_topics | |
if uncategorized_topics.present? | |
totals = get_topic_totals | |
uncategorized = get_uncategorized_category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_uncategorized_category(uncategorized) | |
insert_at = nil | |
@categories.each_with_index do |c, idx| | |
if (uncategorized.topics_week || 0) > (c.topics_week || 0) | |
insert_at = idx | |
break | |
end | |
end | |
@categories.insert(insert_at || @categories.size, uncategorized) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_uncategorized | |
# Support for uncategorized topics | |
uncategorized_topics = get_uncategorized_topics | |
if uncategorized_topics.present? | |
totals = get_topic_totals | |
uncategorized = get_uncategorized_category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uncategorized = get_uncategorized_category | |
def get_uncategorized_category | |
Category.new({name: SiteSetting.uncategorized_name, | |
slug: Slug.for(SiteSetting.uncategorized_name), | |
color: SiteSetting.uncategorized_color, | |
text_color: SiteSetting.uncategorized_text_color, | |
featured_topics: uncategorized_topics}.merge(totals)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
totals = get_topic_totals | |
def get_topic_totals | |
Topic.exec_sql("SELECT SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 WEEK') THEN 1 ELSE 0 END) as topics_week, | |
SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 MONTH') THEN 1 ELSE 0 END) as topics_month, | |
SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 YEAR') THEN 1 ELSE 0 END) as topics_year, | |
COUNT(*) AS topic_count | |
FROM topics | |
WHERE topics.visible | |
AND topics.deleted_at IS NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uncategorized_topics = get_uncategorized_topics | |
def get_uncategorized_topics | |
Topic | |
.listable_topics | |
.visible | |
.where(category_id: nil) | |
.topic_list_order | |
.limit(SiteSetting.category_featured_topics) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_uncategorized | |
# Support for uncategorized topics | |
uncategorized_topics = Topic | |
.listable_topics | |
.visible | |
.where(category_id: nil) | |
.topic_list_order | |
.limit(SiteSetting.category_featured_topics) | |
if uncategorized_topics.present? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchObserver < ActiveRecord::Observer | |
observe :topic, :post, :user, :category | |
def after_save(obj) | |
obj.update_search_data_index | |
end | |
end |