From 337dc6e0add164baa70bea690621fe23191d08a9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 9 Nov 2020 16:00:23 +0100 Subject: Fix updating account counters when account_stat is not yet created (#15108) --- app/models/account_stat.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'app/models') diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index c84e4217c..e70b54d79 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -21,26 +21,26 @@ class AccountStat < ApplicationRecord def increment_count!(key) update(attributes_for_increment(key)) - rescue ActiveRecord::StaleObjectError + rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotUnique begin reload_with_id rescue ActiveRecord::RecordNotFound - # Nothing to do - else - retry + return end + + retry end def decrement_count!(key) - update(key => [public_send(key) - 1, 0].max) - rescue ActiveRecord::StaleObjectError + update(attributes_for_decrement(key)) + rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotUnique begin reload_with_id rescue ActiveRecord::RecordNotFound - # Nothing to do - else - retry + return end + + retry end private @@ -51,8 +51,13 @@ class AccountStat < ApplicationRecord attrs end + def attributes_for_decrement(key) + attrs = { key => [public_send(key) - 1, 0].max } + attrs + end + def reload_with_id - self.id = find_by!(account: account).id if new_record? + self.id = self.class.find_by!(account: account).id if new_record? reload end end -- cgit From 2b1a6e734ff42c17fb971cf909509b6b2ad84879 Mon Sep 17 00:00:00 2001 From: Takeshi Umeda Date: Fri, 13 Nov 2020 00:58:00 +0900 Subject: Add follow selected followers button (#15148) * Add follow selected followers button * Fix unused variable * Fix i18n normalize --- app/controllers/relationships_controller.rb | 4 +++- app/models/form/account_batch.rb | 8 ++++++++ app/views/relationships/show.html.haml | 2 ++ config/locales/en.yml | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/controllers/relationships_controller.rb b/app/controllers/relationships_controller.rb index 0835758f2..031e3241f 100644 --- a/app/controllers/relationships_controller.rb +++ b/app/controllers/relationships_controller.rb @@ -49,7 +49,9 @@ class RelationshipsController < ApplicationController end def action_from_button - if params[:unfollow] + if params[:follow] + 'follow' + elsif params[:unfollow] 'unfollow' elsif params[:remove_from_followers] 'remove_from_followers' diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb index 7b9e40f68..882770d7c 100644 --- a/app/models/form/account_batch.rb +++ b/app/models/form/account_batch.rb @@ -9,6 +9,8 @@ class Form::AccountBatch def save case action + when 'follow' + follow! when 'unfollow' unfollow! when 'remove_from_followers' @@ -24,6 +26,12 @@ class Form::AccountBatch private + def follow! + accounts.find_each do |target_account| + FollowService.new.call(current_account, target_account) + end + end + def unfollow! accounts.find_each do |target_account| UnfollowService.new.call(current_account, target_account) diff --git a/app/views/relationships/show.html.haml b/app/views/relationships/show.html.haml index 4b1e4fd63..c82e639e0 100644 --- a/app/views/relationships/show.html.haml +++ b/app/views/relationships/show.html.haml @@ -42,6 +42,8 @@ %label.batch-table__toolbar__select.batch-checkbox-all = check_box_tag :batch_checkbox_all, nil, false .batch-table__toolbar__actions + = f.button safe_join([fa_icon('user-plus'), t('relationships.follow_selected_followers')]), name: :follow, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') } if followed_by_relationship? && !mutual_relationship? + = f.button safe_join([fa_icon('user-times'), t('relationships.remove_selected_follows')]), name: :unfollow, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') } unless followed_by_relationship? = f.button safe_join([fa_icon('trash'), t('relationships.remove_selected_followers')]), name: :remove_from_followers, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') } unless following_relationship? diff --git a/config/locales/en.yml b/config/locales/en.yml index 02368d900..bec099082 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1075,6 +1075,7 @@ en: relationships: activity: Account activity dormant: Dormant + follow_selected_followers: Follow selected followers followers: Followers following: Following invited: Invited -- cgit From 9870b175b477bbc984fc7945f1ebe07e3f2b0053 Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 12 Nov 2020 18:35:23 +0100 Subject: Fix possible inconsistencies in tag search (#14906) Do not downcase the queried tag before passing it to postgres when searching: - tags are not downcased on creation - `arel_table[:name].lower.matches(pattern)` generates an ILIKE anyway - if Postgres and Rails happen to use different case-folding rules, downcasing before query but not before insertion may mean that some tags with some casings are not searchable --- app/models/tag.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/tag.rb b/app/models/tag.rb index df2f86d95..bb93a52e2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -126,7 +126,7 @@ class Tag < ApplicationRecord end def search_for(term, limit = 5, offset = 0, options = {}) - normalized_term = normalize(term.strip).mb_chars.downcase.to_s + normalized_term = normalize(term.strip) pattern = sanitize_sql_like(normalized_term) + '%' query = Tag.listable.where(arel_table[:name].lower.matches(pattern)) query = query.where(arel_table[:name].lower.eq(normalized_term).or(arel_table[:reviewed_at].not_eq(nil))) if options[:exclude_unreviewed] -- cgit