posts: stop updating fav_string attribute.
Stop updating the fav_string attribute on posts. The column still exists on the table, but is no longer used or updated. Like the pool_string in7d503f08, the fav_string was used in the past to facilitate `fav:X` searches. Posts had a hidden fav_string column that contained a list of every user who favorited the post. These were treated like fake hidden tags on the post so that a search for `fav:X` was treated like a tag search. The fav_string attribute has been unused for search purposes for a while now. It was only kept because of technicalities that required departitioning the favorites table first (340e1008e) before it could be removed. Basically, removing favorites with `@favorite.destroy` was slow because Rails always deletes object by ID, but we didn't have an index on favorites.id, and we couldn't easily add one until the favorites table was departitioned. Fixes #4652. See https://github.com/danbooru/danbooru/issues/4652#issuecomment-754993802 for more discussion of issues caused by the fav_string (in short: write amplification, post table bloat, and favorite inconsistency problems).
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
class FavoritesController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
rescue_with Favorite::Error, status: 422
|
||||
|
||||
def index
|
||||
authorize Favorite
|
||||
@@ -18,23 +17,18 @@ class FavoritesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
authorize Favorite
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.add_favorite!(CurrentUser.user)
|
||||
flash.now[:notice] = "You have favorited this post"
|
||||
@favorite = authorize Favorite.new(post_id: params[:post_id], user: CurrentUser.user)
|
||||
@favorite.save
|
||||
@post = @favorite.post.reload
|
||||
|
||||
flash.now[:notice] = "You have favorited this post"
|
||||
respond_with(@post)
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize Favorite
|
||||
@post = Post.find_by_id(params[:id])
|
||||
|
||||
if @post
|
||||
@post.remove_favorite!(CurrentUser.user)
|
||||
else
|
||||
Favorite.remove(post_id: params[:id], user: CurrentUser.user)
|
||||
end
|
||||
@favorite = authorize Favorite.find_by!(post_id: params[:id], user: CurrentUser.user)
|
||||
@favorite.destroy
|
||||
@post = @favorite.post.reload
|
||||
|
||||
flash.now[:notice] = "You have unfavorited this post"
|
||||
respond_with(@post)
|
||||
|
||||
Reference in New Issue
Block a user