Skip to content

Commit

Permalink
Fix mastodon#1813 - Alleviate extra requests when processing mentions (
Browse files Browse the repository at this point in the history
…mastodon#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
  • Loading branch information
Gargron authored Apr 16, 2017
1 parent 99226ab commit babbb21
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/services/process_feed_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ def mentions_from_xml(parent, xml)
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)

Expand All @@ -178,6 +172,16 @@ def mentions_from_xml(parent, xml)
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)
Expand Down

0 comments on commit babbb21

Please sign in to comment.