|
|
@@ -4,10 +4,15 @@ class TagsController < ApplicationController |
|
|
|
|
|
|
|
|
tags = |
|
|
tags = |
|
|
if post_id.present? |
|
|
if post_id.present? |
|
|
Tag.joins(:posts).where(posts: { id: post_id }) |
|
|
|
|
|
|
|
|
Tag.joins(:posts, :tag_name) |
|
|
else |
|
|
else |
|
|
Tag.all |
|
|
|
|
|
|
|
|
Tag.joins(:tag_name) |
|
|
end |
|
|
end |
|
|
|
|
|
.left_joins(tag_name: :wiki_page) |
|
|
|
|
|
.includes(:tag_name, tag_name: :wiki_page) |
|
|
|
|
|
if post_id.present? |
|
|
|
|
|
tags = tags.where(posts: { id: post_id }) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
render json: tags.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki]) |
|
|
render json: tags.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki]) |
|
|
end |
|
|
end |
|
|
@@ -33,7 +38,9 @@ class TagsController < ApplicationController |
|
|
matched_alias_by_tag_name_id[canonical_id] ||= alias_name |
|
|
matched_alias_by_tag_name_id[canonical_id] ||= alias_name |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
base = Tag.joins(:tag_name).includes(:tag_name) |
|
|
|
|
|
|
|
|
base = Tag.joins(:tag_name) |
|
|
|
|
|
.left_joins(tag_name: :wiki_page) |
|
|
|
|
|
.includes(:tag_name, tag_name: :wiki_page) |
|
|
base = base.where('tags.post_count > 0') if present_only |
|
|
base = base.where('tags.post_count > 0') if present_only |
|
|
|
|
|
|
|
|
canonical_hit = |
|
|
canonical_hit = |
|
|
@@ -58,7 +65,10 @@ class TagsController < ApplicationController |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def show |
|
|
def show |
|
|
tag = Tag.find_by(id: params[:id]) |
|
|
|
|
|
|
|
|
tag = Tag.joins(:tag_name) |
|
|
|
|
|
.left_joins(tag_name: :wiki_page) |
|
|
|
|
|
.includes(:tag_name, tag_name: :wiki_page) |
|
|
|
|
|
.find_by(id: params[:id]) |
|
|
if tag |
|
|
if tag |
|
|
render json: tag.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki]) |
|
|
render json: tag.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki]) |
|
|
else |
|
|
else |
|
|
@@ -70,7 +80,10 @@ class TagsController < ApplicationController |
|
|
name = params[:name].to_s.strip |
|
|
name = params[:name].to_s.strip |
|
|
return head :bad_request if name.blank? |
|
|
return head :bad_request if name.blank? |
|
|
|
|
|
|
|
|
tag = Tag.joins(:tag_name).includes(:tag_name).find_by(tag_names: { name: }) |
|
|
|
|
|
|
|
|
tag = Tag.joins(:tag_name) |
|
|
|
|
|
.left_joins(tag_name: :wiki_page) |
|
|
|
|
|
.includes(:tag_name, tag_name: :wiki_page) |
|
|
|
|
|
.find_by(tag_names: { name: }) |
|
|
if tag |
|
|
if tag |
|
|
render json: tag.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki]) |
|
|
render json: tag.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki]) |
|
|
else |
|
|
else |
|
|
|