related tags: eliminate recent_tags cookie (#3955).
This commit is contained in:
@@ -46,7 +46,6 @@ class PostsController < ApplicationController
|
||||
@post = Post.find(params[:id])
|
||||
|
||||
@post.update(post_params) if @post.visible?
|
||||
save_recent_tags
|
||||
respond_with_post_after_update(@post)
|
||||
end
|
||||
|
||||
@@ -96,15 +95,6 @@ private
|
||||
params[:tags] || (params[:post] && params[:post][:tags])
|
||||
end
|
||||
|
||||
def save_recent_tags
|
||||
if @post
|
||||
tags = Tag.scan_tags(@post.tag_string)
|
||||
tags = (TagAlias.to_aliased(tags) + Tag.scan_tags(cookies[:recent_tags])).uniq.slice(0, 30)
|
||||
cookies[:recent_tags] = tags.join(" ")
|
||||
cookies[:recent_tags_with_categories] = Tag.categories_for(tags).to_a.flatten.join(" ")
|
||||
end
|
||||
end
|
||||
|
||||
def respond_with_post_after_update(post)
|
||||
respond_with(post) do |format|
|
||||
format.html do
|
||||
|
||||
@@ -58,21 +58,11 @@ class UploadsController < ApplicationController
|
||||
flash[:notice] = @service.warnings.join(".\n \n")
|
||||
end
|
||||
|
||||
save_recent_tags
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def save_recent_tags
|
||||
if @upload
|
||||
tags = Tag.scan_tags(@upload.tag_string)
|
||||
tags = (TagAlias.to_aliased(tags) + Tag.scan_tags(cookies[:recent_tags])).compact.uniq.slice(0, 30)
|
||||
cookies[:recent_tags] = tags.join(" ")
|
||||
cookies[:recent_tags_with_categories] = Tag.categories_for(tags).to_a.flatten.join(" ")
|
||||
end
|
||||
end
|
||||
|
||||
def upload_params
|
||||
permitted_params = %i[
|
||||
file source tag_string rating status parent_id artist_commentary_title
|
||||
|
||||
@@ -26,6 +26,17 @@ class RelatedTagQuery
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour.
|
||||
def recent_tags(since: 1.hour.ago, max_edits: 20, max_tags: 20)
|
||||
return [] unless user.present? && PostArchive.enabled?
|
||||
|
||||
versions = PostArchive.where(updater_id: user.id).where("updated_at > ?", since).order(id: :desc).limit(max_edits)
|
||||
tags = versions.flat_map { |v| v.diff[:added_tags] }
|
||||
tags = tags.reject { |tag| Tag.is_metatag?(tag) }
|
||||
tags = tags.group_by(&:itself).transform_values(&:size).sort_by { |tag, count| [-count, tag] }.map(&:first)
|
||||
tags.take(max_tags)
|
||||
end
|
||||
|
||||
def favorite_tags
|
||||
user&.favorite_tags.to_s.split
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<div id="related-tags" class="related-tags">
|
||||
<% if local_assigns[:related_tags] %>
|
||||
<%= render "tag_column", tags: cookies[:recent_tags].to_s.split, title: "Recent" %>
|
||||
<%= render "tag_column", tags: related_tags.recent_tags, title: "Recent" %>
|
||||
<%= render "tag_column", tags: related_tags.favorite_tags, title: "Frequent" %>
|
||||
<%= render "tag_column", tags: related_tags.tags, class: "general-related-tags-column", title: related_tags.pretty_name %>
|
||||
<%= render "tag_column", tags: related_tags.translated_tags, title: "Translated Tags" %>
|
||||
|
||||
Reference in New Issue
Block a user