From a12c61efeaab5de05756decfd1ae7c707c68b804 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Tue, 2 Apr 2013 14:35:14 +0200 Subject: [PATCH] [add] #452 : Better cache dir stucture --- bin/thumb_server.sh | 24 ++++++++++++++---------- index.php | 9 ++++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh index 7d5ffe4..e2195a8 100755 --- a/bin/thumb_server.sh +++ b/bin/thumb_server.sh @@ -15,6 +15,10 @@ randomSleep=`echo $((RANDOM%20))` optimizeTool='' # external tool form optimize png maxQueue=50 # max process in queue currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l) +firstLevel=${md5Site:0:2} +secondLevel=${md5Site:2:2} +startPath=$firstLevel/$secondLevel/ +mkdir -p "cache/img/$startPath" if [ ! -f "cache/config/serverOptions.php" ] then @@ -42,9 +46,9 @@ then echo 0 errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` case $errorCode in - 000) cp "bin/000.png" "cache/img/$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$md5Site.png" ;; - 404) cp "bin/404.png" "cache/img/$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$md5Site.png" ;; - *) cp "bin/error.png" "cache/img/$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$md5Site.png" ;; + 000) cp "bin/000.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$md5Site.png" ;; + 404) cp "bin/404.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$startPath""$md5Site.png" ;; + *) cp "bin/error.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$md5Site.png" ;; esac if $log then @@ -56,31 +60,31 @@ then fi if [ $onlyThumb == 1 ] then - convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png" + convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "cache/img/$md5Site""_thumb.png" + eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png" fi else - convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png" - convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png" + convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$startPath""$md5Site.png" + convert "cache/img/$startPath""$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png" if [ $optimizeTool ] then - eval $optimizeTool "cache/img/$md5Site""_thumb.png" "cache/img/$md5Site.png" + eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png" "cache/img/$startPath""$md5Site.png" fi fi rm "cache/tmp/$md5Site.png" if [ $onlyThumb ] then - if [[ -f "cache/img/$md5Site""_thumb.png" ]] + if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" ]] then echo 1 else echo 0 fi else - if [[ -f "cache/img/$md5Site""_thumb.png" && -f "cache/img/$md5Site.png" ]] + if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" && -f "cache/img/$startPath""$md5Site.png" ]] then echo 1 else diff --git a/index.php b/index.php index 682e63d..cfb49ef 100644 --- a/index.php +++ b/index.php @@ -69,7 +69,6 @@ function testExistImg($file) { } } - /** * Run the bash script for generate thumbnail * @@ -241,7 +240,10 @@ if ($_GET) { } $md5Url = md5($defUrl); - $file = 'cache/img/' . $md5Url; + $startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/'; + $file = 'cache/img/'.$startPath.$md5Url; + + if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) { if (isset($ui['iw']) && (int)$ui['iw'] === 1) { @@ -289,7 +291,8 @@ if ($_POST) { } $md5Url = md5($defUrl); - $file = 'cache/img/' . $md5Url; + $startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/'; + $file = 'cache/img/'.$startPath . $md5Url; if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) { launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true);