changeset 406:1af18eeeffb3

Cache strategy revised to trace icon cache renewal
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 09 Feb 2017 09:38:51 +0900
parents 6244bbb72400
children 4d912c2d48df
files s4-blog.sh
diffstat 1 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/s4-blog.sh	Wed Feb 08 12:53:20 2017 +0900
+++ b/s4-blog.sh	Thu Feb 09 09:38:51 2017 +0900
@@ -223,6 +223,22 @@
     cachedir="$td/$id"; test -d "$cachedir" || mkdir -p "$cachedir"
     cachefile="$cachedir/$id.row"
     stampfile="$cachedir/$id.stamp"
+
+    # First, check the availability of user-icon.
+    # If not existent, clear and reset row cache by rm $stampfile
+    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
+      rm -f "$stampfile"
+      unset stampfile	# No icon-image, do not construct row-cache
+    fi
+
     if test -s "$stampfile" &&
 	  test -s "$cachefile" &&
 	  { ts=`cat "$stampfile"`; test -n "$ts"; } &&
@@ -235,18 +251,7 @@
 	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
-     
-	date "+%F %T" > $stampfile # Cache time stamp(is here good?)
+
 	cat<<EOF
 <tr id="$id">
 <td class="$tdcls">$picon${edit:+<a href="$elink+$edit">編集</a> }#$aid
@@ -295,7 +300,7 @@
 	    		  -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \
 			  -e "s|\$|\">$fnb</a>|"
 		# [ -d $td ] || mkdir -p "$td"
-		rm -f "$stampfile" # img data stream is not suitable to cache
+		unset stampfile # img data stream is not suitable to cache
 		echo $tm > $tsfile
 	      fi
 	      ;;
@@ -306,6 +311,7 @@
 	done
 	echo "</td></tr>"
       } > "$cachefile"	######## New ROW Creation Ends here ########
+      test -n "$stampfile" && date "+%F %T" > $stampfile
     fi
     # Printing a cached row
     sed "/<td class=/s/__NEWCLS__/$new${new:+ }/" $cachefile
@@ -339,7 +345,7 @@
 	<p id="bottom"> </p>
 	EOF
   # Clean up orphaned icon cache
-  [ -s $iconcleaner ] && sq $db < $iconcleaner
+  [ -s $iconcleaner ] && query ".read '$iconcleaner'"
   # Record access log
   acclog blog $rowid
 }

yatex.org