Refactored generation of unique tags, URIs and object URLs into own classes,
as well as formatting of content
This commit is contained in:
parent
735b4cc62e
commit
3cc47beb6e
28 changed files with 316 additions and 180 deletions
|
@ -15,7 +15,7 @@ class FanOutOnWriteService < BaseService
|
|||
|
||||
def deliver_to_followers(status)
|
||||
status.account.followers.each do |follower|
|
||||
next if !follower.local? || FeedManager.filter_status?(status, follower)
|
||||
next if !follower.local? || FeedManager.instance.filter_status?(status, follower)
|
||||
push(:home, follower, status)
|
||||
end
|
||||
end
|
||||
|
@ -29,16 +29,16 @@ class FanOutOnWriteService < BaseService
|
|||
end
|
||||
|
||||
def push(type, receiver, status)
|
||||
redis.zadd(FeedManager.key(type, receiver.id), status.id, status.id)
|
||||
redis.zadd(FeedManager.instance.key(type, receiver.id), status.id, status.id)
|
||||
trim(type, receiver)
|
||||
ActionCable.server.broadcast("timeline:#{receiver.id}", type: 'update', timeline: type, message: inline_render(receiver, status))
|
||||
end
|
||||
|
||||
def trim(type, receiver)
|
||||
return unless redis.zcard(FeedManager.key(type, receiver.id)) > FeedManager::MAX_ITEMS
|
||||
return unless redis.zcard(FeedManager.instance.key(type, receiver.id)) > FeedManager::MAX_ITEMS
|
||||
|
||||
last = redis.zrevrange(FeedManager.key(type, receiver.id), FeedManager::MAX_ITEMS - 1, FeedManager::MAX_ITEMS - 1)
|
||||
redis.zremrangebyscore(FeedManager.key(type, receiver.id), '-inf', "(#{last.last}")
|
||||
last = redis.zrevrange(FeedManager.instance.key(type, receiver.id), FeedManager::MAX_ITEMS - 1, FeedManager::MAX_ITEMS - 1)
|
||||
redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), '-inf', "(#{last.last}")
|
||||
end
|
||||
|
||||
def redis
|
||||
|
|
|
@ -7,8 +7,8 @@ class PrecomputeFeedService < BaseService
|
|||
instant_return = []
|
||||
|
||||
Status.send("as_#{type}_timeline", account).order('created_at desc').limit(FeedManager::MAX_ITEMS).each do |status|
|
||||
next if type == :home && FeedManager.filter_status?(status, account)
|
||||
redis.zadd(FeedManager.key(type, account.id), status.id, status.id)
|
||||
next if type == :home && FeedManager.instance.filter_status?(status, account)
|
||||
redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.id)
|
||||
instant_return << status unless instant_return.size > limit
|
||||
end
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ class ProcessFeedService < BaseService
|
|||
# Also record all media attachments for the status and for the reblogged status if present
|
||||
unless status.new_record?
|
||||
record_remote_mentions(status, entry.xpath('./xmlns:link[@rel="mentioned"]'))
|
||||
|
||||
|
||||
process_attachments(entry, status)
|
||||
process_attachments(entry.xpath('./activity:object'), status.reblog) if status.reblog?
|
||||
|
||||
|
||||
DistributionWorker.perform_async(status.id)
|
||||
end
|
||||
end
|
||||
|
@ -112,8 +112,8 @@ class ProcessFeedService < BaseService
|
|||
def find_original_status(_xml, id)
|
||||
return nil if id.nil?
|
||||
|
||||
if local_id?(id)
|
||||
Status.find(unique_tag_to_local_id(id, 'Status'))
|
||||
if TagManager.instance.local_id?(id)
|
||||
Status.find(TagManager.instance.unique_tag_to_local_id(id, 'Status'))
|
||||
else
|
||||
Status.find_by(uri: id)
|
||||
end
|
||||
|
|
|
@ -45,7 +45,7 @@ class ProcessInteractionService < BaseService
|
|||
end
|
||||
|
||||
def mentions_account?(xml, account)
|
||||
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]').each { |mention_link| return true if mention_link.attribute('href').value == url_for_target(account) }
|
||||
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]').each { |mention_link| return true if mention_link.attribute('href').value == TagManager.instance.url_for(account) }
|
||||
false
|
||||
end
|
||||
|
||||
|
@ -85,7 +85,7 @@ class ProcessInteractionService < BaseService
|
|||
end
|
||||
|
||||
def status(xml)
|
||||
Status.find(unique_tag_to_local_id(activity_id(xml), 'Status'))
|
||||
Status.find(TagManager.instance.unique_tag_to_local_id(activity_id(xml), 'Status'))
|
||||
end
|
||||
|
||||
def activity_id(xml)
|
||||
|
|
|
@ -44,7 +44,7 @@ class RemoveStatusService < BaseService
|
|||
end
|
||||
|
||||
def unpush(type, receiver, status)
|
||||
redis.zremrangebyscore(FeedManager.key(type, receiver.id), status.id, status.id)
|
||||
redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
|
||||
ActionCable.server.broadcast("timeline:#{receiver.id}", type: 'delete', id: status.id)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue