mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: less code for Category#url
This commit is contained in:
parent
09ca75d17e
commit
8851b79472
@ -709,37 +709,29 @@ class Category < ActiveRecord::Base
|
|||||||
].include? id
|
].include? id
|
||||||
end
|
end
|
||||||
|
|
||||||
@@url_cache = DistributedCache.new('category_url')
|
def full_slug(separator = "-")
|
||||||
|
start_idx = "#{Discourse.base_uri}/c/".size
|
||||||
|
url[start_idx..-1].gsub("/", separator)
|
||||||
|
end
|
||||||
|
|
||||||
|
@@url_cache = DistributedCache.new("category_url")
|
||||||
|
|
||||||
def clear_url_cache
|
def clear_url_cache
|
||||||
@@url_cache.clear
|
@@url_cache.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_slug(separator = "-")
|
|
||||||
start_idx = "#{Discourse.base_uri}/c/".length
|
|
||||||
url[start_idx..-1].gsub("/", separator)
|
|
||||||
end
|
|
||||||
|
|
||||||
def url
|
def url
|
||||||
url = @@url_cache[self.id]
|
@@url_cache[self.id] ||= "#{Discourse.base_uri}/c/#{slug_path.join('/')}"
|
||||||
unless url
|
|
||||||
url = "#{Discourse.base_uri}/c/#{slug_path.join('/')}"
|
|
||||||
|
|
||||||
@@url_cache[self.id] = url
|
|
||||||
end
|
|
||||||
|
|
||||||
url
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_with_id
|
def url_with_id
|
||||||
self.parent_category ? "#{url}/#{self.id}" : "#{Discourse.base_uri}/c/#{self.slug}/#{self.id}"
|
self.parent_category ? "#{url}/#{self.id}" : "#{Discourse.base_uri}/c/#{self.slug}/#{self.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# If the name changes, try and update the category definition topic too if it's
|
# If the name changes, try and update the category definition topic too if it's an exact match
|
||||||
# an exact match
|
|
||||||
def rename_category_definition
|
def rename_category_definition
|
||||||
old_name = saved_changes.transform_values(&:first)["name"]
|
|
||||||
return unless topic.present?
|
return unless topic.present?
|
||||||
|
old_name = saved_changes.transform_values(&:first)["name"]
|
||||||
if topic.title == I18n.t("category.topic_prefix", category: old_name)
|
if topic.title == I18n.t("category.topic_prefix", category: old_name)
|
||||||
topic.update_attribute(:title, I18n.t("category.topic_prefix", category: name))
|
topic.update_attribute(:title, I18n.t("category.topic_prefix", category: name))
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user