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 in 7d503f08, 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:
evazion
2021-10-07 23:32:38 -05:00
parent 5ce36b482f
commit 1653392361
17 changed files with 190 additions and 239 deletions

View File

@@ -1,18 +1,22 @@
$("#add-to-favorites, #add-fav-button, #remove-from-favorites, #remove-fav-button").toggle();
$("#remove-fav-button").addClass("animate");
$("span.post-votes[data-id=<%= @post.id %>]").replaceWith("<%= j render_post_votes @post, current_user: CurrentUser.user %>");
$("#favcount-for-post-<%= @post.id %>").text(<%= @post.fav_count %>);
$(".fav-buttons").toggleClass("fav-buttons-false").toggleClass("fav-buttons-true");
<% if @favorite.errors.any? %>
Danbooru.Utility.error("You have already favorited this post");
<% else %>
$("#add-to-favorites, #add-fav-button, #remove-from-favorites, #remove-fav-button").toggle();
$("#remove-fav-button").addClass("animate");
$("span.post-votes[data-id=<%= @post.id %>]").replaceWith("<%= j render_post_votes @post, current_user: CurrentUser.user %>");
$("#favcount-for-post-<%= @post.id %>").text(<%= @post.fav_count %>);
$(".fav-buttons").toggleClass("fav-buttons-false").toggleClass("fav-buttons-true");
<% if policy(@post).can_view_favlist? %>
var fav_count = <%= @post.fav_count %>;
$("#favlist").html("<%= j render "posts/partials/show/favorite_list", post: @post %>");
<% if policy(@post).can_view_favlist? %>
var fav_count = <%= @post.fav_count %>;
$("#favlist").html("<%= j render "posts/partials/show/favorite_list", post: @post %>");
if (fav_count === 0) {
$("#show-favlist-link, #hide-favlist-link, #favlist").hide();
} else if (!$("#favlist").is(":visible")) {
$("#show-favlist-link").show();
}
if (fav_count === 0) {
$("#show-favlist-link, #hide-favlist-link, #favlist").hide();
} else if (!$("#favlist").is(":visible")) {
$("#show-favlist-link").show();
}
<% end %>
Danbooru.Utility.notice("<%= j flash[:notice] %>");
<% end %>
Danbooru.Utility.notice("<%= j flash[:notice] %>");