0
0
Fork 0

Slightly reduce RAM usage (#7301)

* No need to re-require sidekiq plugins, they are required via Gemfile

* Add derailed_benchmarks tool, no need to require TTY gems in Gemfile

* Replace ruby-oembed with FetchOEmbedService

Reduce startup by 45382 allocated objects

* Remove preloaded JSON-LD in favour of caching HTTP responses

Reduce boot RAM by about 6 MiB

* Fix tests

* Fix test suite by stubbing out JSON-LD contexts
This commit is contained in:
Eugen Rochko 2018-05-02 18:58:48 +02:00 committed by GitHub
parent 71a7cea73f
commit cb5b5cb5f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 784 additions and 471 deletions

View file

@ -85,42 +85,40 @@ class FetchLinkCardService < BaseService
end
def attempt_oembed
embed = OEmbed::Providers.get(@url, html: @html)
embed = FetchOEmbedService.new.call(@url, html: @html)
return false unless embed.respond_to?(:type)
return false if embed.nil?
@card.type = embed.type
@card.title = embed.respond_to?(:title) ? embed.title : ''
@card.author_name = embed.respond_to?(:author_name) ? embed.author_name : ''
@card.author_url = embed.respond_to?(:author_url) ? embed.author_url : ''
@card.provider_name = embed.respond_to?(:provider_name) ? embed.provider_name : ''
@card.provider_url = embed.respond_to?(:provider_url) ? embed.provider_url : ''
@card.type = embed[:type]
@card.title = embed[:title] || ''
@card.author_name = embed[:author_name] || ''
@card.author_url = embed[:author_url] || ''
@card.provider_name = embed[:provider_name] || ''
@card.provider_url = embed[:provider_url] || ''
@card.width = 0
@card.height = 0
case @card.type
when 'link'
@card.image_remote_url = embed.thumbnail_url if embed.respond_to?(:thumbnail_url)
@card.image_remote_url = embed[:thumbnail_url] if embed[:thumbnail_url].present?
when 'photo'
return false unless embed.respond_to?(:url)
return false if embed[:url].blank?
@card.embed_url = embed.url
@card.image_remote_url = embed.url
@card.width = embed.width.presence || 0
@card.height = embed.height.presence || 0
@card.embed_url = embed[:url]
@card.image_remote_url = embed[:url]
@card.width = embed[:width].presence || 0
@card.height = embed[:height].presence || 0
when 'video'
@card.width = embed.width.presence || 0
@card.height = embed.height.presence || 0
@card.html = Formatter.instance.sanitize(embed.html, Sanitize::Config::MASTODON_OEMBED)
@card.image_remote_url = embed.thumbnail_url if embed.respond_to?(:thumbnail_url)
@card.width = embed[:width].presence || 0
@card.height = embed[:height].presence || 0
@card.html = Formatter.instance.sanitize(embed[:html], Sanitize::Config::MASTODON_OEMBED)
@card.image_remote_url = embed[:thumbnail_url] if embed[:thumbnail_url].present?
when 'rich'
# Most providers rely on <script> tags, which is a no-no
return false
end
@card.save_with_optional_image!
rescue OEmbed::NotFound
false
end
def attempt_opengraph