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:
@@ -22,7 +22,7 @@ module Explore
|
||||
context "#curated" do
|
||||
should "render" do
|
||||
@builder = create(:builder_user)
|
||||
@post.add_favorite!(@builder)
|
||||
Favorite.create!(post: @post, user: @builder)
|
||||
get curated_explore_posts_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
|
||||
@user = create(:user)
|
||||
@post = create(:post)
|
||||
@faved_post = create(:post)
|
||||
@faved_post.add_favorite!(@user)
|
||||
create(:favorite, post: @faved_post, user: @user)
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
@@ -33,30 +33,48 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "create action" do
|
||||
should "create a favorite for the current user" do
|
||||
assert_difference("Favorite.count", 1) do
|
||||
assert_difference [-> { @post.favorites.count }, -> { @post.reload.fav_count }, -> { @user.reload.favorite_count }], 1 do
|
||||
post_auth favorites_path(post_id: @post.id), @user, as: :javascript
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
|
||||
should "not allow creating duplicate favorites" do
|
||||
create(:favorite, post: @post, user: @user)
|
||||
|
||||
assert_no_difference [-> { @post.favorites.count }, -> { @post.reload.fav_count }, -> { @user.reload.favorite_count }] do
|
||||
post_auth favorites_path(post_id: @post.id), @user, as: :javascript
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
|
||||
should "allow banned users to create favorites" do
|
||||
assert_difference("Favorite.count", 1) do
|
||||
post_auth favorites_path(post_id: @post.id), create(:banned_user), as: :javascript
|
||||
@banned_user = create(:banned_user)
|
||||
|
||||
assert_difference [-> { @post.favorites.count }, -> { @post.reload.fav_count }, -> { @banned_user.reload.favorite_count }], 1 do
|
||||
post_auth favorites_path(post_id: @post.id), @banned_user, as: :javascript
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
|
||||
should "not allow anonymous users to create favorites" do
|
||||
assert_no_difference [-> { @post.favorites.count }, -> { @post.reload.fav_count }] do
|
||||
post favorites_path(post_id: @post.id), as: :javascript
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
should "remove the favorite from the current user" do
|
||||
assert_difference("Favorite.count", -1) do
|
||||
should "remove the favorite for the current user" do
|
||||
assert_difference [-> { @faved_post.favorites.count }, -> { @faved_post.reload.fav_count }, -> { @user.reload.favorite_count }], -1 do
|
||||
delete_auth favorite_path(@faved_post.id), @user, as: :javascript
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
|
||||
should "allow banned users to destroy favorites" do
|
||||
assert_difference("Favorite.count", -1) do
|
||||
assert_difference [-> { @faved_post.favorites.count }, -> { @faved_post.reload.fav_count }, -> { @user.reload.favorite_count }], -1 do
|
||||
delete_auth favorite_path(@faved_post.id), @user, as: :javascript
|
||||
assert_response :redirect
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ module Moderator
|
||||
end
|
||||
users = FactoryBot.create_list(:user, 2)
|
||||
users.each do |u|
|
||||
@child.add_favorite!(u)
|
||||
Favorite.create!(post: @child, user: u)
|
||||
@child.reload
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user