]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Cache cacheUrl information to avoid slowness due to excessive curls calls
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 26 Mar 2017 01:08:01 +0000 (22:08 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 26 Mar 2017 01:08:01 +0000 (22:08 -0300)
data/templates/default/bookmarks.tpl.php

index 4f22e915293a9ec4d185f37e6ad8c70a2ea7de83..6b8a7c7b6cc1902fa4dd13abec6af93689a86aa4 100644 (file)
@@ -338,6 +338,7 @@ if ($currenttag!= '') {
                }
 
     // Local cache
+    $cacheInfo = $GLOBALS['dir_cache'] .'/urls';
     $cacheLink = null;
     if ($GLOBALS['cacheUrl'] != null) {
       // Hashing discussion at http://linuxprocess.free.fr/MHonArc/Oct-2005/msg00016.html
@@ -348,13 +349,29 @@ if ($currenttag!= '') {
       $assetPng  = $assetLink .'/screenshot.png';
 
       // Check if the link exists
-      if ($fp = curl_init($assetLink)) {
+      if (file_exists($cacheInfo .'/' $assetHash .'/hascache')) {
+        $cacheLink = "| <a href=\"$assetLink\">Cache</a>";
+
+        if (file_exists($cacheInfo .'/' $assetHash .'/haspdf')) {
+          $cacheLink .= " | <a href=\"$assetPdf\">PDF</a>";
+        }
+
+        if (file_exists($cacheInfo .'/' $assetHash .'/haspng')) {
+          $cacheLink .= " | <a href=\"$assetPng\">PNG</a>";
+        }
+      }
+      else if ($fp = curl_init($assetLink)) {
         curl_setopt($fp, CURLOPT_NOBODY, true);
         curl_exec($fp);
 
         $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE);
 
         if ($retcode != 404) {
+          if (!file_exists($cacheInfo .'/' $assetHash)) {
+            mkdir($cacheInfo .'/' $assetHash);
+          }
+
+          touch($cacheInfo .'/' $assetHash .'/hascache');
           $cacheLink = "| <a href=\"$assetLink\">Cache</a>";
 
           // Check if PDF is available
@@ -365,6 +382,7 @@ if ($currenttag!= '') {
             $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE);
 
             if ($retcode != 404) {
+              touch($cacheInfo .'/' $assetHash .'/haspdf');
               $cacheLink .= " | <a href=\"$assetPdf\">PDF</a>";
             }
 
@@ -379,6 +397,7 @@ if ($currenttag!= '') {
             $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE);
 
             if ($retcode != 404) {
+              touch($cacheInfo .'/' $assetHash .'/haspng');
               $cacheLink .= " | <a href=\"$assetPng\">PNG</a>";
             }