s4
changeset 391:554dc6669027
Icon cache'ing refined
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 29 Nov 2016 13:18:47 +0859 |
parents | 5a40f38d7daf |
children | be955399aec9 |
files | s4-funcs.sh |
diffstat | 1 files changed, 17 insertions(+), 8 deletions(-) [+] |
line diff
1.1 --- a/s4-funcs.sh Mon Nov 28 19:04:20 2016 +0859 1.2 +++ b/s4-funcs.sh Tue Nov 29 13:18:47 2016 +0859 1.3 @@ -1608,6 +1608,7 @@ 1.4 whos="$keycond AND key='profimg' AND type LIKE 'file:image%' 1.5 ORDER BY rowid DESC LIMIT 1" 1.6 [ -d "$dir" ] || mkdir -p "$dir" 1.7 + tmpf=$tmpd/imgsrc_cache.$$ 1.8 case "$4" in 1.9 [Ss]) size=S ;; 1.10 [Oo]) size=O ;; 1.11 @@ -1631,13 +1632,16 @@ 1.12 cacheimg_O=$dir/$filename 1.13 cacheimg=$dir/${size}_$filename 1.14 sumfile="$dir/$filename.sum" 1.15 - tmpf=$tmpd/imgsrc_cache.$$ 1.16 sum=`query "$sql1" | tee $tmpf | encode` # encode() is maybe sha1 1.17 - if test -s "$sumfile" && [ x"`cat $sumfile`" = x"$sum" ]; then 1.18 - # if cache is fresh, 1.19 + if test -s "$sumfile" && [ x"`cat \"$sumfile\"`" = x"$sum" ] \ 1.20 + && test -s "$cacheimg_S" && test -s "$cacheimg_M" ; then 1.21 + # if cache is fresh and has the same checksum, 1.22 echo "<img src=\"$cacheimg\">" 1.23 else 1.24 - fifo=$tmpd/fifo; mkfifo $fifo 1.25 + fifo=`mktemp "$tmpf.fifo.XXXXXXX"` 1.26 + rm -f $fifo # Safe, because $tmpf is in mktemp dir. 1.27 + fifo2=$fifo.2 1.28 + mkfifo $fifo $fifo2 1.29 fmt=${filename##*.} 1.30 ## [[ NOTE ]] 1.31 ## a. convert oldimage newimage 1.32 @@ -1647,12 +1651,13 @@ 1.33 | tee $fifo \ 1.34 | convert -define ${fmt}:size=${iconxy_M}x${iconxy_M} \ 1.35 -resize ${iconxy_M}x${iconxy_M}'>' - ${fmt}:- \ 1.36 + | tee $fifo2 \ 1.37 | convert - "$cacheimg_M" & 1.38 cat $fifo | convert -define ${fmt}:size=${iconxy_S}x${iconxy_S} \ 1.39 -resize ${iconxy_S}x${iconxy_S}'>' - ${fmt}:- \ 1.40 | convert - "$cacheimg_S" & 1.41 printf '%s' "<img src=\"data:${filetype}," 1.42 - cat $tmpf | sed 's/\(..\)/%\1/g' 1.43 + hexize "$fifo2" |sed 's/\(..\)/%\1/g' # Use medium as pre-cached image 1.44 echo '">' 1.45 echo "$sum" > $sumfile 1.46 fi 1.47 @@ -2013,6 +2018,7 @@ 1.48 echo $pnbtn 1.49 1.50 ## err ListEntry: `echo "$sql"\;` 1.51 +# sq $db here??? 2016-11-28 1.52 query "$sql limit $limit ${offset:+offset $offset};" \ 1.53 | while IFS='|' read id lnk name qname icon gecos tag ownerp type; do 1.54 err name=$name owner=$ownerp lnk=$lnk 1.55 @@ -2022,7 +2028,7 @@ 1.56 echo "<div class=\"iconlist xy$thumbxy $type\"> 1.57 <p class=\"tag _$tag\">$tag</p>" \ 1.58 | _m4 $tagconv 1.59 - if [ -z "NOSPEEDUP" ]; then 1.60 + if [ -n "$NOSPEEDUP" ]; then 1.61 files=`getvalbyid $tbl profimg $id $icondir` 1.62 if [ -n "$files" ]; then 1.63 icon=`echo "$files"|tail -1` 1.64 @@ -2031,7 +2037,7 @@ 1.65 iconhref "$dir/$deficon" "$hrb+$lnk" "$gecos" 1.66 fi 1.67 elif [ -n "$icon" -a -s "$icon" ]; then 1.68 - iconhref2 "./$icon" "$hrb+$lnk" "$gecos" 1.69 + iconhref2 "$icon" "$hrb+$lnk" "$gecos" 1.70 else 1.71 cond="$nm=$qname" 1.72 # err imgsrc_cache "$dir/list" ${tbl}_m "$cond" S 1.73 @@ -2040,7 +2046,7 @@ 1.74 # err "img=[$img]" 1.75 if [ -n "$img" ]; then 1.76 echo "<a href=\"$hrb+$lnk\">" 1.77 - imgsrc_cache "$dir/list" ${tbl}_m "$nm=$qname" S 1.78 + imgsrc_cache "$icondir" ${tbl}_m "$nm=$qname" S 1.79 echo "</a>" 1.80 else 1.81 iconhref2 "$dir/$deficon" "$hrb+$lnk" "$gecos" 1.82 @@ -3324,9 +3330,11 @@ 1.83 prompt='' # Remove prompt 1.84 ;; 1.85 [Aa][Uu][Tt][Hh][Oo][Rr]) 1.86 + [ -n "$GF_VIEWONLY" ] && continue 1.87 form="<input type=\"hidden\" name=\"author\" value=\"$user\">" 1.88 prompt="" ;; 1.89 [Oo][Ww][Nn][Ee][Rr]) 1.90 + [ -n "$GF_VIEWONLY" ] && continue 1.91 val=${GF_OWNER:-$val} 1.92 val=${val:-$user} 1.93 form="<input type=\"hidden\" name=\"owner\" value=\"$val\">" 1.94 @@ -3343,6 +3351,7 @@ 1.95 val="" 1.96 ;; 1.97 [Ss][Ee][Rr][Ii][Aa][Ll]|[Ss][Tt][Aa][Mm][Pp]) 1.98 + [ -n "$GF_VIEWONLY" ] && continue 1.99 if [ -z "$rowid" ]; then 1.100 val=`genserial` 1.101 fi