changeset 264:9131c7e09112

Use cache file for article images.
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 21 Jul 2016 18:02:08 +0859
parents ebd4af16c493
children 5323bf64f05c
files s4-blog.sh
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/s4-blog.sh	Wed Jul 20 21:50:06 2016 +0859
+++ b/s4-blog.sh	Thu Jul 21 18:02:08 2016 +0859
@@ -188,6 +188,7 @@
 ${notify:+$nt}</td><td>`echo "$hte"|unhexize|htmlescape`
 EOF
     hreflink
+    usecache='' tsfile=$td/$id.stamp
     for i in $imgids; do
       mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
       fn=`echo "${i#*:}"|unhexize`
@@ -201,6 +202,7 @@
 	    *.[Gg][Ii][Ff])	fmt=gif ;;
 	    *)		fmt=jpeg ;;
 	  esac
+	  if false; then	# This block should be removed
 	  sq $db "SELECT hex(bin) FROM article_m WHERE rowid=$mrid" \
 	      | unhexize \
 	      | convert -define ${fmt}:size=100x100 -resize 100x100'>' - ${fmt}:- \
@@ -208,6 +210,39 @@
 	      | sed -e 's/\(..\)/%\1/g' \
 	    	    -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \
 		    -e "s|\$|\">$fnb</a>|"
+	  else
+	    outfile=$td/$mrid-${fn%.*}.$fmt
+	    #err fn=$fn outfile=$outfile
+	    #err "`ls -Fa $td`"
+	    #rm -f $outfile
+	    # mkfifo $outfile
+	    #err "usecache=$usecache `ls -l $outfile`" 
+	    #err tm=$tm
+	    #err tsfile=$tsfile=`cat $tsfile`
+	    if [ -s $outfile ] &&	# $outfile should be > 0
+		   { [ "$usecache" ] ||	# And usecache flag is true, or...
+			 { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ]
+			 };}; then
+	      # err Set usecache=1
+	      usecache=1		# Set usecache flag on
+	      cat<<-EOF
+		<a href="$catlink+$mrid"><img src="$outfile">
+		$fnb</a>
+		EOF
+	    else
+	      query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \
+		  | unhexize \
+		  | convert -define ${fmt}:size=100x100 -resize 100x100'>' \
+			    - ${fmt}:- \
+		  | tee "$outfile" \
+		  | hexize \
+		  | sed -e 's/\(..\)/%\1/g' \
+	    		-e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \
+			-e "s|\$|\">$fnb</a>|"
+	      [ -d $td ] || mkdir -p "$td"
+	      echo $tm > $tsfile
+	    fi
+	  fi
 	  ;;
 	*)
 	  echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"

yatex.org