diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-08-19 19:31:32 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-08-19 21:49:35 +0200 |
commit | 1488be7d9683fb3442c6f7bd4fd911d224f0c929 (patch) | |
tree | 42548a596bb118e08c14c4d0ae9eacb3e8b2f36b /lib | |
parent | b859eb001717dfc62aebb8eba47b84c75aebe4ef (diff) | |
parent | d22f3a7d5140ef1c3ae6e9bd2241bbb5289af8d1 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - app/controllers/home_controller.rb - app/controllers/shares_controller.rb - app/javascript/packs/public.js - app/models/status.rb - app/serializers/initial_state_serializer.rb - app/views/home/index.html.haml - app/views/layouts/public.html.haml - app/views/public_timelines/show.html.haml - app/views/shares/show.html.haml - app/views/tags/show.html.haml - config/initializers/content_security_policy.rb - config/locales/en.yml - config/webpack/shared.js - package.json
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/accounts_cli.rb | 10 | ||||
-rw-r--r-- | lib/mastodon/cache_cli.rb | 45 |
2 files changed, 52 insertions, 3 deletions
diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb index 7d0215313..d1854acc0 100644 --- a/lib/mastodon/accounts_cli.rb +++ b/lib/mastodon/accounts_cli.rb @@ -314,11 +314,15 @@ module Mastodon desc 'follow ACCT', 'Make all local accounts follow account specified by ACCT' long_desc <<-LONG_DESC - Make all local accounts follow an account specified by ACCT. ACCT can be - a simple username, in case of a local user. It can also be in the format - username@domain, in case of a remote user. + Make all local accounts follow another local account specified by ACCT. + ACCT should be the username only. LONG_DESC def follow(acct) + if acct.include? '@' + say('Target account name should not contain a target instance, since it has to be a local account.', :red) + exit(1) + end + target_account = ResolveAccountService.new.call(acct) processed = 0 failed = 0 diff --git a/lib/mastodon/cache_cli.rb b/lib/mastodon/cache_cli.rb index e9b6667b3..5b0eea91b 100644 --- a/lib/mastodon/cache_cli.rb +++ b/lib/mastodon/cache_cli.rb @@ -15,5 +15,50 @@ module Mastodon Rails.cache.clear say('OK', :green) end + + desc 'recount TYPE', 'Update hard-cached counters' + long_desc <<~LONG_DESC + Update hard-cached counters of TYPE by counting referenced + records from scratch. TYPE can be "accounts" or "statuses". + + It may take a very long time to finish, depending on the + size of the database. + LONG_DESC + def recount(type) + processed = 0 + + case type + when 'accounts' + Account.local.includes(:account_stat).find_each do |account| + account_stat = account.account_stat + account_stat.following_count = account.active_relationships.count + account_stat.followers_count = account.passive_relationships.count + account_stat.statuses_count = account.statuses.where.not(visibility: :direct).count + + account_stat.save if account_stat.changed? + + processed += 1 + say('.', :green, false) + end + when 'statuses' + Status.includes(:status_stat).find_each do |status| + status_stat = status.status_stat + status_stat.replies_count = status.replies.where.not(visibility: :direct).count + status_stat.reblogs_count = status.reblogs.count + status_stat.favourites_count = status.favourites.count + + status_stat.save if status_stat.changed? + + processed += 1 + say('.', :green, false) + end + else + say("Unknown type: #{type}", :red) + exit(1) + end + + say + say("OK, recounted #{processed} records", :green) + end end end |