cache open graph response (#17157)
* Trigger Build * Cache the HTML response for quicker previews * remove unnecessary comments
This commit is contained in:
parent
e4446a778c
commit
dfdae481e4
1 changed files with 9 additions and 1 deletions
|
|
@ -9,9 +9,11 @@ class OpenGraph
|
|||
attr_reader :page, :tags
|
||||
|
||||
DEFAULT_METHODS = %i[description title url].freeze
|
||||
CACHE_EXPIRY_IN_MINUTES = 15
|
||||
|
||||
def initialize(url)
|
||||
@page = MetaInspector.new(url)
|
||||
html = fetch_html(url)
|
||||
@page = MetaInspector.new(url, document: html)
|
||||
@tags = meta_tags
|
||||
end
|
||||
|
||||
|
|
@ -80,6 +82,12 @@ class OpenGraph
|
|||
|
||||
private
|
||||
|
||||
def fetch_html(url)
|
||||
Rails.cache.fetch("#{url}_open_graph_html", expires_in: CACHE_EXPIRY_IN_MINUTES.minutes) do
|
||||
Net::HTTP.get(URI(url))
|
||||
end
|
||||
end
|
||||
|
||||
def group(data)
|
||||
data.each_with_object({}) do |(key, value), hash|
|
||||
group_key = key.split(":").first
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue