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 wrap: on
line diff
--- a/s4-blog.sh	Sun May 03 16:50:46 2020 +0900
+++ b/s4-blog.sh	Sun May 03 19:06:59 2020 +0900
@@ -208,8 +208,9 @@
   $isgrpadmin &&
       href5="<a href=\"?blogseen+$rowid\" accesskey=\"s\" title=\"S\"> 読刻</a>"
   quizmodefile=$tmpd/quiz; rm -f "$quizmodefile"	# XXX: Global state
+  midfile=$tmpd/midfile
 
-  query<<-EOF |
+  query<<-EOF > $midfile
 	SELECT coalesce((SELECT "yes" FROM blog
 			-- GrpAdmin CAN EDIT heading since 2019-08-15
 			 WHERE '$isgrpadmin' = 'true'
@@ -226,11 +227,8 @@
 	       END
 	FROM $ts WHERE id='$id' GROUP BY id;
 	EOF
-  { IFS='|' read edit ctime hexhead blogtype
-    if [ -z "$ctime" ]; then	# Maybe database timeout
-      echo "時間をおいて繋いでください(Please visit later)." | html p
-      return
-    fi
+  if test -s $midfile && IFS='|' read edit ctime hexhead blogtype < $midfile
+  then
     cat<<-EOF
 	<tr><td>${edit:+$href }$ctime $blogtype $href2$href3 $href4 $href5</td></tr>
 	<tr class="preface${frozen_class:+ }$frozen_class">
@@ -245,15 +243,17 @@
     echo '<table class="blog_replies"> <!-- blog:blog_showentry() main table -->'
     if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"XXXX集計" ]; then
       if $isgroup; then
-	if ! isgrpowner "$user" "$blogowner"; then
-	  qgrp=`sqlquote "$blogowner"`
-	  cat<<-EOF > $quizmodefile
+	# Failsafe to query timeout
+	qgrp=`sqlquote "$blogowner"`
+	cat<<-EOF > $quizmodefile
 		AND  (author IN (SELECT user FROM grp_adm WHERE gname=$qgrp)
 		      OR
 		      author='$user')
 		EOF
+	if isgrpowner "$user" "$blogowner"; then
+	  : > $quizmodefile
 	fi
-      else		# if user's blog
+      else		# if user-blog
 	if [ x"$user" != x"$blogowner" ]; then
 	  cat<<-EOF > $quizmodefile
 		AND author IN ('$blogowner', '$user')
@@ -261,7 +261,10 @@
 	fi
       fi
     fi
-  }
+  else		# Cannot read SQL output
+    echo "時間をおいて繋いでください(Please visit later)." | html p
+    return
+  fi
   lkhome="<a href=\"$myname?home" lke='">'
   lkedit="<a href=\"$myname?editart"
   hlink="$myname?home" elink="$myname?editart"
@@ -276,7 +279,6 @@
   # because the next block in pipe line uses query() repeatedly.
   ###### TEST: 2020-04-23 Use intermediate file to shorten duration of db-lock
   ###### sq $db<<EOF |
-  midfile=$tmpd/midfile
   query <<EOF > $midfile
 WITH a_s AS (
   SELECT id,

yatex.org