changeset 403:3ea86fe63490

Introduce row-cache for replyblog()
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 08 Feb 2017 12:11:08 +0900
parents 58c291b6a81f
children 084a4d35c98f
files s4-blog.sh
diffstat 1 files changed, 77 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/s4-blog.sh	Mon Jan 30 19:59:32 2017 +0900
+++ b/s4-blog.sh	Wed Feb 08 12:11:08 2017 +0900
@@ -220,76 +220,93 @@
   ON a.id=s.id;
 EOF
   while IFS='|' read id edit notify uid uname icon aid tm new hte imgids; do
-    nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"
-	 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
-    tdcls="repatt${new:+ new}"
-    if [ -n "$icon" -a -s "$icon" ]; then
-      icfn=`echo "$icon"|htmlescape`
-      picon="<p class=\"proficon\"><a href=\"$hlink+$uid\"><img src=\"$icfn\"></a></p>"
+    cachedir="$td/$id"; test -d "$cachedir" || mkdir -p "$cachedir"
+    cachefile="$cachedir/$id.row"
+    stampfile="$cachedir/$id.stamp"
+    if test -s "$stampfile" &&
+	  test -s "$cachefile" &&
+	  { ts=`cat "$stampfile"`; test -n "$ts"; } &&
+	  test "$ts" '>' "$tm"; then
+	#sed "/<td class=/s/__NEWCLS__/$new/" $cachefile
+	#continue			# And continue to next loop
+      : Nothing to do
     else
-      picon=""
-      if [ -n "$icon" ]; then
-	echo "DELETE FROM user_s WHERE key='$iconcachekey' AND
-	      val=`sqlquotestr \"$icon\"`;" >> $iconcleaner
-      fi
-    fi
-    
-    cat<<EOF
+      {		######## New ROW creation begins here ######## >$cachefile
+	nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"
+	 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
+	tdcls="__NEWCLS__repatt"
+	if [ -n "$icon" -a -s "$icon" ]; then
+	  icfn=`echo "$icon"|htmlescape`
+	  picon="<p class=\"proficon\"><a href=\"$hlink+$uid\"><img src=\"$icfn\"></a></p>"
+	else
+	  picon=""
+	  if [ -n "$icon" ]; then
+	    echo "DELETE FROM user_s WHERE key='$iconcachekey' AND
+	    	        val=`sqlquotestr \"$icon\"`;" >> $iconcleaner
+	  fi
+	fi
+     
+	cat<<EOF
 <tr id="$id">
 <td class="$tdcls">$picon${edit:+<a href="$elink+$edit">編集</a> }#$aid
 <a href="$hlink+$uid">$uname</a>
 $tm
 ${notify:+$nt}</td>
 EOF
-    echo -n "<td id=\"$aid\" class=\"repl\">"
-    echo "$hte"|unhexize|htmlescape|hreflink|minitbl
-    usecache='' tsfile=$td/$id.stamp
-    for i in $imgids; do
-      mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
-      fn=`echo "${i#*:}"|unhexize`
-      fnb=$fn"(${sz})"
-      case "$fn" in
-	*.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[Gg][Ii][Ff])
-	  #  fmt=${fn##*.}	# convert - jpg:- is slow...why
+	echo -n "<td id=\"$aid\" class=\"repl\">"
+	echo "$hte"|unhexize|htmlescape|hreflink|minitbl
+	usecache='' tsfile=$td/$id.stamp
+	for i in $imgids; do
+	  mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
+	  fn=`echo "${i#*:}"|unhexize`
+	  fnb=$fn"(${sz})"
 	  case "$fn" in
-	    *.[Pp][Nn][Gg])	fmt=png ;;
-	    *.[Gg][Ii][Ff])	fmt=gif ;;
-	    *)		fmt=jpeg ;;
-	  esac
-	  outfile=$td/$mrid-${fn%.*}.$fmt
-	  #err fn=$fn outfile=$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
-	    usecache=1		# Set usecache flag on
-	    cat<<-EOF
+	    *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[Gg][Ii][Ff])
+	      #  fmt=${fn##*.}	# convert - jpg:- is slow...why
+	      case "$fn" in
+		*.[Pp][Nn][Gg])	fmt=png ;;
+		*.[Gg][Ii][Ff])	fmt=gif ;;
+		*)		fmt=jpeg ;;
+	      esac
+	      outfile=$td/$mrid-${fn%.*}.$fmt
+	      #err fn=$fn outfile=$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
+		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
-	  ;;
-	*)
-	  echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
-	  ;;
-      esac
-    done
-    echo "</td></tr>"
+	      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
+	      ;;
+	    *)
+	      echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
+	      ;;
+	  esac
+	done
+	date "+%F %T" > $stampfile
+	echo "</td></tr>"
+      } > "$cachefile"	######## New ROW Creation Ends here ########
+    fi
+    # Printing a cached row
+    sed "/<td class=/s/__NEWCLS__/$new${new:+ }/" $cachefile
   done
 
   textform='<div class="fold">
@@ -320,7 +337,7 @@
 	<p id="bottom"> </p>
 	EOF
   # Clean up orphaned icon cache
-  [ -s $iconcleaner ] && query < $iconcleaner
+  [ -s $iconcleaner ] && sq $db < $iconcleaner
   # Record access log
   acclog blog $rowid
 }

yatex.org