s4
changeset 640:b7aeab02d242
Check the SQL output size in case of DB timeout
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sun, 03 May 2020 19:06:59 +0900 |
parents | 1c36cb1a1a0e |
children | a1bcb043589e |
files | s4-blog.sh |
diffstat | 1 files changed, 14 insertions(+), 12 deletions(-) [+] |
line diff
1.1 --- a/s4-blog.sh Sun May 03 16:50:46 2020 +0900 1.2 +++ b/s4-blog.sh Sun May 03 19:06:59 2020 +0900 1.3 @@ -208,8 +208,9 @@ 1.4 $isgrpadmin && 1.5 href5="<a href=\"?blogseen+$rowid\" accesskey=\"s\" title=\"S\"> 読刻</a>" 1.6 quizmodefile=$tmpd/quiz; rm -f "$quizmodefile" # XXX: Global state 1.7 + midfile=$tmpd/midfile 1.8 1.9 - query<<-EOF | 1.10 + query<<-EOF > $midfile 1.11 SELECT coalesce((SELECT "yes" FROM blog 1.12 -- GrpAdmin CAN EDIT heading since 2019-08-15 1.13 WHERE '$isgrpadmin' = 'true' 1.14 @@ -226,11 +227,8 @@ 1.15 END 1.16 FROM $ts WHERE id='$id' GROUP BY id; 1.17 EOF 1.18 - { IFS='|' read edit ctime hexhead blogtype 1.19 - if [ -z "$ctime" ]; then # Maybe database timeout 1.20 - echo "時間をおいて繋いでください(Please visit later)." | html p 1.21 - return 1.22 - fi 1.23 + if test -s $midfile && IFS='|' read edit ctime hexhead blogtype < $midfile 1.24 + then 1.25 cat<<-EOF 1.26 <tr><td>${edit:+$href }$ctime $blogtype $href2$href3 $href4 $href5</td></tr> 1.27 <tr class="preface${frozen_class:+ }$frozen_class"> 1.28 @@ -245,15 +243,17 @@ 1.29 echo '<table class="blog_replies"> <!-- blog:blog_showentry() main table -->' 1.30 if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"XXXX集計" ]; then 1.31 if $isgroup; then 1.32 - if ! isgrpowner "$user" "$blogowner"; then 1.33 - qgrp=`sqlquote "$blogowner"` 1.34 - cat<<-EOF > $quizmodefile 1.35 + # Failsafe to query timeout 1.36 + qgrp=`sqlquote "$blogowner"` 1.37 + cat<<-EOF > $quizmodefile 1.38 AND (author IN (SELECT user FROM grp_adm WHERE gname=$qgrp) 1.39 OR 1.40 author='$user') 1.41 EOF 1.42 + if isgrpowner "$user" "$blogowner"; then 1.43 + : > $quizmodefile 1.44 fi 1.45 - else # if user's blog 1.46 + else # if user-blog 1.47 if [ x"$user" != x"$blogowner" ]; then 1.48 cat<<-EOF > $quizmodefile 1.49 AND author IN ('$blogowner', '$user') 1.50 @@ -261,7 +261,10 @@ 1.51 fi 1.52 fi 1.53 fi 1.54 - } 1.55 + else # Cannot read SQL output 1.56 + echo "時間をおいて繋いでください(Please visit later)." | html p 1.57 + return 1.58 + fi 1.59 lkhome="<a href=\"$myname?home" lke='">' 1.60 lkedit="<a href=\"$myname?editart" 1.61 hlink="$myname?home" elink="$myname?editart" 1.62 @@ -276,7 +279,6 @@ 1.63 # because the next block in pipe line uses query() repeatedly. 1.64 ###### TEST: 2020-04-23 Use intermediate file to shorten duration of db-lock 1.65 ###### sq $db<<EOF | 1.66 - midfile=$tmpd/midfile 1.67 query <<EOF > $midfile 1.68 WITH a_s AS ( 1.69 SELECT id,