about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-16 18:01:48 +0200
committerGitHub <noreply@github.com>2017-04-16 18:01:48 +0200
commitbabbb2135e07faf74df19676c5ab886265890043 (patch)
treed2a485a5832f80ec5f86e605bc0da8af755007e4 /app
parent99226aba9391535a20d3cc6dba0f45e5792c73d4 (diff)
Fix #1813 - Alleviate extra requests when processing mentions (#1938)
The <link rel="mentioned" /> tag refers to accounts by href. So we were
matching the DB by the url attribute, and falling back to HTTP look-up.
However, GS and Mastodon use profile URLs as URIs, too, and the match
for that was missing. This could potentially alleviate some extra network
requests
Diffstat (limited to 'app')
-rw-r--r--app/services/process_feed_service.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index fa0633b27..64a531e74 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -161,13 +161,7 @@ class ProcessFeedService < BaseService
       xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link|
         next if [TagManager::TYPES[:group], TagManager::TYPES[:collection]].include? link['ostatus:object-type']
 
-        url = Addressable::URI.parse(link['href'])
-
-        mentioned_account = if TagManager.instance.web_domain?(url.host)
-                              Account.find_local(url.path.gsub('/users/', ''))
-                            else
-                              Account.find_by(url: link['href']) || FetchRemoteAccountService.new.call(link['href'])
-                            end
+        mentioned_account = account_from_href(link['href'])
 
         next if mentioned_account.nil? || processed_account_ids.include?(mentioned_account.id)
 
@@ -178,6 +172,16 @@ class ProcessFeedService < BaseService
       end
     end
 
+    def account_from_href(href)
+      url = Addressable::URI.parse(href)
+
+      if TagManager.instance.web_domain?(url.host)
+        Account.find_local(url.path.gsub('/users/', ''))
+      else
+        Account.find_by(uri: href) || Account.find_by(url: href) || FetchRemoteAccountService.new.call(href)
+      end
+    end
+
     def hashtags_from_xml(parent, xml)
       tags = xml.xpath('./xmlns:category', xmlns: TagManager::XMLNS).map { |category| category['term'] }.select(&:present?)
       ProcessHashtagsService.new.call(parent, tags)