s4
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 diff
1.1 --- a/s4-blog.sh Mon Jan 30 19:59:32 2017 +0900 1.2 +++ b/s4-blog.sh Wed Feb 08 12:11:08 2017 +0900 1.3 @@ -220,76 +220,93 @@ 1.4 ON a.id=s.id; 1.5 EOF 1.6 while IFS='|' read id edit notify uid uname icon aid tm new hte imgids; do 1.7 - nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\" 1.8 + cachedir="$td/$id"; test -d "$cachedir" || mkdir -p "$cachedir" 1.9 + cachefile="$cachedir/$id.row" 1.10 + stampfile="$cachedir/$id.stamp" 1.11 + if test -s "$stampfile" && 1.12 + test -s "$cachefile" && 1.13 + { ts=`cat "$stampfile"`; test -n "$ts"; } && 1.14 + test "$ts" '>' "$tm"; then 1.15 + #sed "/<td class=/s/__NEWCLS__/$new/" $cachefile 1.16 + #continue # And continue to next loop 1.17 + : Nothing to do 1.18 + else 1.19 + { ######## New ROW creation begins here ######## >$cachefile 1.20 + nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\" 1.21 name=\"notifyto\" value=\"$uid\">返信通知送信</label>" 1.22 - tdcls="repatt${new:+ new}" 1.23 - if [ -n "$icon" -a -s "$icon" ]; then 1.24 - icfn=`echo "$icon"|htmlescape` 1.25 - picon="<p class=\"proficon\"><a href=\"$hlink+$uid\"><img src=\"$icfn\"></a></p>" 1.26 - else 1.27 - picon="" 1.28 - if [ -n "$icon" ]; then 1.29 - echo "DELETE FROM user_s WHERE key='$iconcachekey' AND 1.30 - val=`sqlquotestr \"$icon\"`;" >> $iconcleaner 1.31 - fi 1.32 - fi 1.33 - 1.34 - cat<<EOF 1.35 + tdcls="__NEWCLS__repatt" 1.36 + if [ -n "$icon" -a -s "$icon" ]; then 1.37 + icfn=`echo "$icon"|htmlescape` 1.38 + picon="<p class=\"proficon\"><a href=\"$hlink+$uid\"><img src=\"$icfn\"></a></p>" 1.39 + else 1.40 + picon="" 1.41 + if [ -n "$icon" ]; then 1.42 + echo "DELETE FROM user_s WHERE key='$iconcachekey' AND 1.43 + val=`sqlquotestr \"$icon\"`;" >> $iconcleaner 1.44 + fi 1.45 + fi 1.46 + 1.47 + cat<<EOF 1.48 <tr id="$id"> 1.49 <td class="$tdcls">$picon${edit:+<a href="$elink+$edit">編集</a> }#$aid 1.50 <a href="$hlink+$uid">$uname</a> 1.51 $tm 1.52 ${notify:+$nt}</td> 1.53 EOF 1.54 - echo -n "<td id=\"$aid\" class=\"repl\">" 1.55 - echo "$hte"|unhexize|htmlescape|hreflink|minitbl 1.56 - usecache='' tsfile=$td/$id.stamp 1.57 - for i in $imgids; do 1.58 - mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}` 1.59 - fn=`echo "${i#*:}"|unhexize` 1.60 - fnb=$fn"(${sz})" 1.61 - case "$fn" in 1.62 - *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[Gg][Ii][Ff]) 1.63 - # fmt=${fn##*.} # convert - jpg:- is slow...why 1.64 + echo -n "<td id=\"$aid\" class=\"repl\">" 1.65 + echo "$hte"|unhexize|htmlescape|hreflink|minitbl 1.66 + usecache='' tsfile=$td/$id.stamp 1.67 + for i in $imgids; do 1.68 + mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}` 1.69 + fn=`echo "${i#*:}"|unhexize` 1.70 + fnb=$fn"(${sz})" 1.71 case "$fn" in 1.72 - *.[Pp][Nn][Gg]) fmt=png ;; 1.73 - *.[Gg][Ii][Ff]) fmt=gif ;; 1.74 - *) fmt=jpeg ;; 1.75 - esac 1.76 - outfile=$td/$mrid-${fn%.*}.$fmt 1.77 - #err fn=$fn outfile=$outfile 1.78 - #err "usecache=$usecache `ls -l $outfile`" 1.79 - #err tm=$tm 1.80 - #err tsfile=$tsfile=`cat $tsfile` 1.81 - if [ -s "$outfile" ] && # $outfile should be > 0 1.82 - { [ "$usecache" ] || # And usecache flag is true, or... 1.83 - { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ] 1.84 - };}; then 1.85 - usecache=1 # Set usecache flag on 1.86 - cat<<-EOF 1.87 + *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[Gg][Ii][Ff]) 1.88 + # fmt=${fn##*.} # convert - jpg:- is slow...why 1.89 + case "$fn" in 1.90 + *.[Pp][Nn][Gg]) fmt=png ;; 1.91 + *.[Gg][Ii][Ff]) fmt=gif ;; 1.92 + *) fmt=jpeg ;; 1.93 + esac 1.94 + outfile=$td/$mrid-${fn%.*}.$fmt 1.95 + #err fn=$fn outfile=$outfile 1.96 + #err "usecache=$usecache `ls -l $outfile`" 1.97 + #err tm=$tm 1.98 + #err tsfile=$tsfile=`cat $tsfile` 1.99 + if [ -s "$outfile" ] && # $outfile should be > 0 1.100 + { [ "$usecache" ] || # And usecache flag is true, or... 1.101 + { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ] 1.102 + };}; then 1.103 + usecache=1 # Set usecache flag on 1.104 + cat<<-EOF 1.105 <a href="$catlink+$mrid"><img src="$outfile"> 1.106 $fnb</a> 1.107 EOF 1.108 - else 1.109 - query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \ 1.110 - | unhexize \ 1.111 - | convert -define ${fmt}:size=100x100 -resize 100x100'>' \ 1.112 - - ${fmt}:- \ 1.113 - | tee "$outfile" \ 1.114 - | hexize \ 1.115 - | sed -e 's/\(..\)/%\1/g' \ 1.116 - -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \ 1.117 - -e "s|\$|\">$fnb</a>|" 1.118 - # [ -d $td ] || mkdir -p "$td" 1.119 - echo $tm > $tsfile 1.120 - fi 1.121 - ;; 1.122 - *) 1.123 - echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>" 1.124 - ;; 1.125 - esac 1.126 - done 1.127 - echo "</td></tr>" 1.128 + else 1.129 + query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \ 1.130 + | unhexize \ 1.131 + | convert -define ${fmt}:size=100x100 -resize 100x100'>' \ 1.132 + - ${fmt}:- \ 1.133 + | tee "$outfile" \ 1.134 + | hexize \ 1.135 + | sed -e 's/\(..\)/%\1/g' \ 1.136 + -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \ 1.137 + -e "s|\$|\">$fnb</a>|" 1.138 + # [ -d $td ] || mkdir -p "$td" 1.139 + echo $tm > $tsfile 1.140 + fi 1.141 + ;; 1.142 + *) 1.143 + echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>" 1.144 + ;; 1.145 + esac 1.146 + done 1.147 + date "+%F %T" > $stampfile 1.148 + echo "</td></tr>" 1.149 + } > "$cachefile" ######## New ROW Creation Ends here ######## 1.150 + fi 1.151 + # Printing a cached row 1.152 + sed "/<td class=/s/__NEWCLS__/$new${new:+ }/" $cachefile 1.153 done 1.154 1.155 textform='<div class="fold"> 1.156 @@ -320,7 +337,7 @@ 1.157 <p id="bottom"> </p> 1.158 EOF 1.159 # Clean up orphaned icon cache 1.160 - [ -s $iconcleaner ] && query < $iconcleaner 1.161 + [ -s $iconcleaner ] && sq $db < $iconcleaner 1.162 # Record access log 1.163 acclog blog $rowid 1.164 }