[add] #452 : Better cache dir stucture

This commit is contained in:
Knah Tsaeb 2013-04-02 14:35:14 +02:00
parent 7675edb5de
commit a12c61efea
2 changed files with 20 additions and 13 deletions

View file

@ -15,6 +15,10 @@ randomSleep=`echo $((RANDOM%20))`
optimizeTool='' # external tool form optimize png optimizeTool='' # external tool form optimize png
maxQueue=50 # max process in queue maxQueue=50 # max process in queue
currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l) 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" ] if [ ! -f "cache/config/serverOptions.php" ]
then then
@ -42,9 +46,9 @@ then
echo 0 echo 0
errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)`
case $errorCode in case $errorCode in
000) cp "bin/000.png" "cache/img/$md5Site""_thumb.png" && cp "bin/000.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/$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$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/$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$md5Site.png" ;; *) cp "bin/error.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$md5Site.png" ;;
esac esac
if $log if $log
then then
@ -56,31 +60,31 @@ then
fi fi
if [ $onlyThumb == 1 ] if [ $onlyThumb == 1 ]
then 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 ] if [ $optimizeTool ]
then then
eval $optimizeTool "cache/img/$md5Site""_thumb.png" eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png"
fi fi
else else
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png" convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$startPath""$md5Site.png"
convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png" convert "cache/img/$startPath""$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png"
if [ $optimizeTool ] if [ $optimizeTool ]
then 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
fi fi
rm "cache/tmp/$md5Site.png" rm "cache/tmp/$md5Site.png"
if [ $onlyThumb ] if [ $onlyThumb ]
then then
if [[ -f "cache/img/$md5Site""_thumb.png" ]] if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" ]]
then then
echo 1 echo 1
else else
echo 0 echo 0
fi fi
else 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 then
echo 1 echo 1
else else

View file

@ -69,7 +69,6 @@ function testExistImg($file) {
} }
} }
/** /**
* Run the bash script for generate thumbnail * Run the bash script for generate thumbnail
* *
@ -241,7 +240,10 @@ if ($_GET) {
} }
$md5Url = md5($defUrl); $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 (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
if (isset($ui['iw']) && (int)$ui['iw'] === 1) { if (isset($ui['iw']) && (int)$ui['iw'] === 1) {
@ -289,7 +291,8 @@ if ($_POST) {
} }
$md5Url = md5($defUrl); $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 (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true); launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true);