about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-03-28 04:44:59 +0100
committerGitHub <noreply@github.com>2019-03-28 04:44:59 +0100
commitf1bc90ab508cbdebc646324f87db48a9e80036f4 (patch)
treec9e6fff16d8e69ed99e7010cabd4d83d595e5493 /app/lib
parentf46f67d984e4e2deb4bf98cd5c5de813caf66eca (diff)
Rename :poll to :preloadable_poll and :owned_poll to :poll on Status (#10401)
Also, fix some n+1 queries

Resolve #10365
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activitypub/activity/create.rb10
-rw-r--r--app/lib/activitypub/activity/update.rb4
-rw-r--r--app/lib/formatter.rb4
3 files changed, 9 insertions, 9 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 8fe7b9138..dabdcbcf7 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -68,7 +68,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
         thread: replied_to_status,
         conversation: conversation_from_uri(@object['conversation']),
         media_attachment_ids: process_attachments.take(4).map(&:id),
-        owned_poll: process_poll,
+        poll: process_poll,
       }
     end
   end
@@ -240,11 +240,11 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
   end
 
   def poll_vote?
-    return false if replied_to_status.nil? || replied_to_status.poll.nil? || !replied_to_status.local? || !replied_to_status.poll.options.include?(@object['name'])
+    return false if replied_to_status.nil? || replied_to_status.preloadable_poll.nil? || !replied_to_status.local? || !replied_to_status.preloadable_poll.options.include?(@object['name'])
 
-    unless replied_to_status.poll.expired?
-      replied_to_status.poll.votes.create!(account: @account, choice: replied_to_status.poll.options.index(@object['name']), uri: @object['id'])
-      ActivityPub::DistributePollUpdateWorker.perform_in(3.minutes, replied_to_status.id) unless replied_to_status.poll.hide_totals?
+    unless replied_to_status.preloadable_poll.expired?
+      replied_to_status.preloadable_poll.votes.create!(account: @account, choice: replied_to_status.preloadable_poll.options.index(@object['name']), uri: @object['id'])
+      ActivityPub::DistributePollUpdateWorker.perform_in(3.minutes, replied_to_status.id) unless replied_to_status.preloadable_poll.hide_totals?
     end
 
     true
diff --git a/app/lib/activitypub/activity/update.rb b/app/lib/activitypub/activity/update.rb
index bc9a63f98..70035325b 100644
--- a/app/lib/activitypub/activity/update.rb
+++ b/app/lib/activitypub/activity/update.rb
@@ -23,8 +23,8 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
     return reject_payload! if invalid_origin?(@object['id'])
 
     status = Status.find_by(uri: object_uri, account_id: @account.id)
-    return if status.nil? || status.poll.nil?
+    return if status.nil? || status.preloadable_poll.nil?
 
-    ActivityPub::ProcessPollService.new.call(status.poll, @object)
+    ActivityPub::ProcessPollService.new.call(status.preloadable_poll, @object)
   end
 end
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index aadf03b2a..59dfc9004 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -19,8 +19,8 @@ class Formatter
 
     raw_content = status.text
 
-    if options[:inline_poll_options] && status.poll
-      raw_content = raw_content + "\n\n" + status.poll.options.map { |title| "[ ] #{title}" }.join("\n")
+    if options[:inline_poll_options] && status.preloadable_poll
+      raw_content = raw_content + "\n\n" + status.preloadable_poll.options.map { |title| "[ ] #{title}" }.join("\n")
     end
 
     return '' if raw_content.blank?