diff app/helpers/application_helper.rb @ 103:1251b3d6ec5d

Use included url data instead of expanding using embiggen
author nanaya <me@myconan.net>
date Mon, 26 Sep 2016 02:39:40 +0900
parents c5c095f6981e
children 950849c40d42
line wrap: on
line diff
--- a/app/helpers/application_helper.rb	Fri Sep 23 23:10:54 2016 +0900
+++ b/app/helpers/application_helper.rb	Mon Sep 26 02:39:40 2016 +0900
@@ -13,11 +13,20 @@
     "tag:#{request.host_with_port},2005:#{id}"
   end
 
-  def expand_url(text)
+  def expand_url(text, *urls)
+    urls.flatten!
+
+    urls = urls.reduce({}) do |result, u|
+      if u.try(:[], :url)
+        result[u[:url]] = u[:expanded_url]
+        @any = 1
+      end
+
+      result
+    end
+
     text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
-      Rails.cache.fetch url, :expires_in => 1.hour do
-        " #{Embiggen::URI(url).expand} "
-      end
+      urls[url] || url
     end
   end
 end