about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/favourite.rb2
-rw-r--r--app/models/follow.rb4
-rw-r--r--app/models/import.rb14
-rw-r--r--app/models/status.rb4
4 files changed, 19 insertions, 5 deletions
diff --git a/app/models/favourite.rb b/app/models/favourite.rb
index 67a293888..41d06e734 100644
--- a/app/models/favourite.rb
+++ b/app/models/favourite.rb
@@ -4,7 +4,7 @@ class Favourite < ApplicationRecord
   include Paginable
 
   belongs_to :account, inverse_of: :favourites
-  belongs_to :status,  inverse_of: :favourites
+  belongs_to :status,  inverse_of: :favourites, counter_cache: true
 
   has_one :notification, as: :activity, dependent: :destroy
 
diff --git a/app/models/follow.rb b/app/models/follow.rb
index 57db8c462..8bfe8b2f6 100644
--- a/app/models/follow.rb
+++ b/app/models/follow.rb
@@ -3,8 +3,8 @@
 class Follow < ApplicationRecord
   include Paginable
 
-  belongs_to :account
-  belongs_to :target_account, class_name: 'Account'
+  belongs_to :account, counter_cache: :following_count
+  belongs_to :target_account, class_name: 'Account', counter_cache: :followers_count
 
   has_one :notification, as: :activity, dependent: :destroy
 
diff --git a/app/models/import.rb b/app/models/import.rb
new file mode 100644
index 000000000..255063c53
--- /dev/null
+++ b/app/models/import.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class Import < ApplicationRecord
+  self.inheritance_column = false
+
+  enum type: [:following, :blocking]
+
+  belongs_to :account
+
+  FILE_TYPES = ['text/plain', 'text/csv'].freeze
+
+  has_attached_file :data, url: '/system/:hash.:extension', hash_secret: ENV.fetch('PAPERCLIP_SECRET')
+  validates_attachment_content_type :data, content_type: FILE_TYPES
+end
diff --git a/app/models/status.rb b/app/models/status.rb
index d5bbf70fb..81b26fd14 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -10,11 +10,11 @@ class Status < ApplicationRecord
 
   belongs_to :application, class_name: 'Doorkeeper::Application'
 
-  belongs_to :account, inverse_of: :statuses
+  belongs_to :account, inverse_of: :statuses, counter_cache: true
   belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account'
 
   belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies
-  belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs
+  belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, counter_cache: :reblogs_count
 
   has_many :favourites, inverse_of: :status, dependent: :destroy
   has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy