# HG changeset patch # User HIROSE Yuuji # Date 1486523468 -32400 # Node ID 3ea86fe6349084913fbd15bf898ec21781f62ce3 # Parent 58c291b6a81f4104b190fbbfc72deafa9d543c46 Introduce row-cache for replyblog() diff -r 58c291b6a81f -r 3ea86fe63490 s4-blog.sh --- 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="" - tdcls="repatt${new:+ new}" - if [ -n "$icon" -a -s "$icon" ]; then - icfn=`echo "$icon"|htmlescape` - picon="

" + 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 "/> $iconcleaner - fi - fi - - cat<$cachefile + nt="" + tdcls="__NEWCLS__repatt" + if [ -n "$icon" -a -s "$icon" ]; then + icfn=`echo "$icon"|htmlescape` + picon="

" + else + picon="" + if [ -n "$icon" ]; then + echo "DELETE FROM user_s WHERE key='$iconcachekey' AND + val=`sqlquotestr \"$icon\"`;" >> $iconcleaner + fi + fi + + cat< $picon${edit:+編集 }#$aid $uname $tm ${notify:+$nt} EOF - echo -n "" - 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 "" + 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 $fnb 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|^|$fnb|" - # [ -d $td ] || mkdir -p "$td" - echo $tm > $tsfile - fi - ;; - *) - echo "$fnb" - ;; - esac - done - echo "" + 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|^|$fnb|" + # [ -d $td ] || mkdir -p "$td" + echo $tm > $tsfile + fi + ;; + *) + echo "$fnb" + ;; + esac + done + date "+%F %T" > $stampfile + echo "" + } > "$cachefile" ######## New ROW Creation Ends here ######## + fi + # Printing a cached row + sed "/