From de24e70ae17850b12ff8ac69439da86bb6d77d74 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 25 Mar 2017 22:08:01 -0300 Subject: Cache cacheUrl information to avoid slowness due to excessive curls calls --- data/templates/default/bookmarks.tpl.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/data/templates/default/bookmarks.tpl.php b/data/templates/default/bookmarks.tpl.php index 4f22e91..6b8a7c7 100644 --- a/data/templates/default/bookmarks.tpl.php +++ b/data/templates/default/bookmarks.tpl.php @@ -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 = "| Cache"; + + if (file_exists($cacheInfo .'/' $assetHash .'/haspdf')) { + $cacheLink .= " | PDF"; + } + + if (file_exists($cacheInfo .'/' $assetHash .'/haspng')) { + $cacheLink .= " | PNG"; + } + } + 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 = "| Cache"; // 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 .= " | PDF"; } @@ -379,6 +397,7 @@ if ($currenttag!= '') { $retcode = curl_getinfo($fp, CURLINFO_HTTP_CODE); if ($retcode != 404) { + touch($cacheInfo .'/' $assetHash .'/haspng'); $cacheLink .= " | PNG"; } -- cgit v1.2.3