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/block.rb5
-rw-r--r--app/models/feed.rb12
-rw-r--r--app/models/follow.rb9
-rw-r--r--app/models/follow_request.rb5
-rw-r--r--app/models/mention.rb5
-rw-r--r--app/models/report.rb1
-rw-r--r--app/models/status.rb6
7 files changed, 18 insertions, 25 deletions
diff --git a/app/models/block.rb b/app/models/block.rb
index 9c55703c9..ae456a6b6 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -3,9 +3,8 @@
 class Block < ApplicationRecord
   include Paginable
 
-  belongs_to :account
-  belongs_to :target_account, class_name: 'Account'
+  belongs_to :account, required: true
+  belongs_to :target_account, class_name: 'Account', required: true
 
-  validates :account, :target_account, presence: true
   validates :account_id, uniqueness: { scope: :target_account_id }
 end
diff --git a/app/models/feed.rb b/app/models/feed.rb
index 5e1905e15..3cbc160a0 100644
--- a/app/models/feed.rb
+++ b/app/models/feed.rb
@@ -10,17 +10,9 @@ class Feed
     max_id     = '+inf' if max_id.blank?
     since_id   = '-inf' if since_id.blank?
     unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:last).map(&:to_i)
+    status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
 
-    # If we're after most recent items and none are there, we need to precompute the feed
-    if unhydrated.empty? && max_id == '+inf' && since_id == '-inf'
-      RegenerationWorker.perform_async(@account.id, @type)
-      @statuses = Status.send("as_#{@type}_timeline", @account).cache_ids.paginate_by_max_id(limit, nil, nil)
-    else
-      status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
-      @statuses  = unhydrated.map { |id| status_map[id] }.compact
-    end
-
-    @statuses
+    unhydrated.map { |id| status_map[id] }.compact
   end
 
   private
diff --git a/app/models/follow.rb b/app/models/follow.rb
index 8bfe8b2f6..b6b9dca7c 100644
--- a/app/models/follow.rb
+++ b/app/models/follow.rb
@@ -3,11 +3,14 @@
 class Follow < ApplicationRecord
   include Paginable
 
-  belongs_to :account, counter_cache: :following_count
-  belongs_to :target_account, class_name: 'Account', counter_cache: :followers_count
+  belongs_to :account, counter_cache: :following_count, required: true
+
+  belongs_to :target_account,
+             class_name: 'Account',
+             counter_cache: :followers_count,
+             required: true
 
   has_one :notification, as: :activity, dependent: :destroy
 
-  validates :account, :target_account, presence: true
   validates :account_id, uniqueness: { scope: :target_account_id }
 end
diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb
index 4224ab15d..20e1332dd 100644
--- a/app/models/follow_request.rb
+++ b/app/models/follow_request.rb
@@ -3,12 +3,11 @@
 class FollowRequest < ApplicationRecord
   include Paginable
 
-  belongs_to :account
-  belongs_to :target_account, class_name: 'Account'
+  belongs_to :account, required: true
+  belongs_to :target_account, class_name: 'Account', required: true
 
   has_one :notification, as: :activity, dependent: :destroy
 
-  validates :account, :target_account, presence: true
   validates :account_id, uniqueness: { scope: :target_account_id }
 
   def authorize!
diff --git a/app/models/mention.rb b/app/models/mention.rb
index 10a9cb1cd..03e76fcc4 100644
--- a/app/models/mention.rb
+++ b/app/models/mention.rb
@@ -1,11 +1,10 @@
 # frozen_string_literal: true
 
 class Mention < ApplicationRecord
-  belongs_to :account, inverse_of: :mentions
-  belongs_to :status
+  belongs_to :account, inverse_of: :mentions, required: true
+  belongs_to :status, required: true
 
   has_one :notification, as: :activity, dependent: :destroy
 
-  validates :account, :status, presence: true
   validates :account, uniqueness: { scope: :status }
 end
diff --git a/app/models/report.rb b/app/models/report.rb
index 05dc8cff1..fd8e46aac 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -3,6 +3,7 @@
 class Report < ApplicationRecord
   belongs_to :account
   belongs_to :target_account, class_name: 'Account'
+  belongs_to :action_taken_by_account, class_name: 'Account'
 
   scope :unresolved, -> { where(action_taken: false) }
   scope :resolved,   -> { where(action_taken: true) }
diff --git a/app/models/status.rb b/app/models/status.rb
index 81b26fd14..6948ad77c 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -161,9 +161,9 @@ class Status < ApplicationRecord
       return where.not(visibility: [:private, :direct]) if account.nil?
 
       if target_account.blocking?(account) # get rid of blocked peeps
-        where('1 = 0')
+        none
       elsif account.id == target_account.id # author can see own stuff
-        where('1 = 1')
+        all
       elsif account.following?(target_account) # followers can see followers-only stuff, but also things they are mentioned in
         joins('LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = ' + account.id.to_s)
           .where('statuses.visibility != ? OR mentions.id IS NOT NULL', Status.visibilities[:direct])
@@ -188,7 +188,7 @@ class Status < ApplicationRecord
   end
 
   before_validation do
-    text.strip!
+    text&.strip!
     spoiler_text&.strip!
 
     self.reply                  = !(in_reply_to_id.nil? && thread.nil?) unless reply