The code powering m.abunchtell.com https://m.abunchtell.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

65 rindas
1.9 KiB

  1. # frozen_string_literal: true
  2. require_relative '../../config/boot'
  3. require_relative '../../config/environment'
  4. require_relative 'cli_helper'
  5. module Mastodon
  6. class CacheCLI < Thor
  7. def self.exit_on_failure?
  8. true
  9. end
  10. desc 'clear', 'Clear out the cache storage'
  11. def clear
  12. Rails.cache.clear
  13. say('OK', :green)
  14. end
  15. desc 'recount TYPE', 'Update hard-cached counters'
  16. long_desc <<~LONG_DESC
  17. Update hard-cached counters of TYPE by counting referenced
  18. records from scratch. TYPE can be "accounts" or "statuses".
  19. It may take a very long time to finish, depending on the
  20. size of the database.
  21. LONG_DESC
  22. def recount(type)
  23. processed = 0
  24. case type
  25. when 'accounts'
  26. Account.local.includes(:account_stat).find_each do |account|
  27. account_stat = account.account_stat
  28. account_stat.following_count = account.active_relationships.count
  29. account_stat.followers_count = account.passive_relationships.count
  30. account_stat.statuses_count = account.statuses.where.not(visibility: :direct).count
  31. account_stat.save if account_stat.changed?
  32. processed += 1
  33. say('.', :green, false)
  34. end
  35. when 'statuses'
  36. Status.includes(:status_stat).find_each do |status|
  37. status_stat = status.status_stat
  38. status_stat.replies_count = status.replies.where.not(visibility: :direct).count
  39. status_stat.reblogs_count = status.reblogs.count
  40. status_stat.favourites_count = status.favourites.count
  41. status_stat.save if status_stat.changed?
  42. processed += 1
  43. say('.', :green, false)
  44. end
  45. else
  46. say("Unknown type: #{type}", :red)
  47. exit(1)
  48. end
  49. say
  50. say("OK, recounted #{processed} records", :green)
  51. end
  52. end
  53. end