s4

changeset 568:3cb5c360e1bf

Try to speed up user-home summary construction.
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 22 Apr 2019 12:03:16 +0900
parents 5b911fee7e1b
children 81b5ec847687
files s4-funcs.sh
diffstat 1 files changed, 36 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Mon Apr 22 12:02:33 2019 +0900
     1.2 +++ b/s4-funcs.sh	Mon Apr 22 12:03:16 2019 +0900
     1.3 @@ -381,7 +381,8 @@
     1.4  # We want to use piped function to put querylog, but we use
     1.5  # simple redirection for the sake of speed.
     1.6  query() {
     1.7 -  echo ".once $sqo" >&5
     1.8 +  # echo ".once $sqo" >&5
     1.9 +  echo ".output $sqo" >&5
    1.10    logstart
    1.11    if [ -z "$1" ]; then
    1.12      tee -a $querylog
    1.13 @@ -389,6 +390,7 @@
    1.14      echo "$@" >> $querylog
    1.15      echo "$@"
    1.16    fi  >&5
    1.17 +  echo ".output stdout" >&5
    1.18    cat $sqo
    1.19    logend
    1.20  }
    1.21 @@ -1876,7 +1878,12 @@
    1.22    fi
    1.23    nblog=`query "SELECT count(id) FROM blog_s WHERE key='owner' AND \
    1.24  		val='$uname';"`
    1.25 +  ## REMOVE This comment block until 2019/7/1
    1.26 +  ## err "----- `gdate +%FT%T.%3N` ------------C"
    1.27 +  ## [ x"$user" = x'yuuji@gentei.org' ] && ddd=1
    1.28    listblog $uname			> $bf
    1.29 +  ## unset ddd
    1.30 +  ## err "----- `gdate +%FT%T.%3N` ------------D"
    1.31  
    1.32    hometail=$tmpd/tail.$$
    1.33    mkfifo $hometail
    1.34 @@ -3131,6 +3138,7 @@
    1.35    fi
    1.36    sqlfile=$tmpd/dump.sql
    1.37    : > $sqlfile			# ensure to be empty
    1.38 +  printf '.mode html\n.header 1\n' > $sqlfile
    1.39    # $DT_CHLD=ChildTable:BindColumn
    1.40    if [ -n "$DT_CHLD" ]; then
    1.41      _t=${DT_CHLD%:*} _i=${DT_CHLD#*:}
    1.42 @@ -3142,6 +3150,7 @@
    1.43      # Speed up counting of new articles
    1.44      cat<<-EOF >> $sqlfile
    1.45  	-- presql2
    1.46 +	DROP TABLE IF EXISTS _counts;
    1.47  	CREATE TEMPORARY TABLE _counts AS
    1.48  	  SELECT $_i, count($_i) cnt
    1.49  	  FROM $_t GROUP BY $_i;
    1.50 @@ -3152,14 +3161,20 @@
    1.51  	      ON b.id=s.id AND s.key='owner'
    1.52  	      ${DT_QOWNER:+ AND s.val=$DT_QOWNER};
    1.53  
    1.54 +	DROP TABLE IF EXISTS _children;
    1.55  	CREATE TEMPORARY TABLE _children AS
    1.56  	  SELECT a.trowid trowid, $_i, a.id, s.val ctime
    1.57  	  FROM   (SELECT t.trowid, t.id $_i, a.id
    1.58            	  FROM _target t LEFT JOIN "$_t" a ON t.id=a.$_i) a
    1.59            LEFT JOIN ${_t}_s s ON a.id=s.id AND s.key='ctime';
    1.60  
    1.61 -	CREATE TEMPORARY TABLE _news($_i, newcnt);
    1.62 -	  INSERT INTO _news
    1.63 +	-- ${ddd:+.system gdate +%T.%3N >> tmp/d1}
    1.64 +	DROP TABLE IF EXISTS _news;
    1.65 +
    1.66 +	-- CREATE TEMPORARY TABLE _news($_i, newcnt);
    1.67 +	--  INSERT INTO _news
    1.68 +	/* **COMPARE** the efficiency of TEMP-TABLE and VIEW !!! */
    1.69 +	CREATE VIEW _news AS (
    1.70      	  SELECT a.id, coalesce(newcnt, 0) newcnt
    1.71      	  FROM   (SELECT DISTINCT id FROM _target)
    1.72  	      a LEFT JOIN
    1.73 @@ -3169,7 +3184,8 @@
    1.74                                            WHERE tblrowid=x.trowid),
    1.75                                 	         '1970-01-01')
    1.76                    GROUP BY $_i) b
    1.77 -          ON a.id=b.$_i;
    1.78 +          ON a.id=b.$_i);
    1.79 +	-- ${ddd:+.system gdate +%T.%3N >> tmp/d1}
    1.80  	EOF
    1.81      # REMOVE next line until 2019/5/1
    1.82      cntall="(select count($_i) from $_t where $_i=a.id)"
    1.83 @@ -3232,15 +3248,30 @@
    1.84  	*** SQL-file: $sqlfile ***
    1.85  	`cat $sqlfile`
    1.86  	EOF
    1.87 +  if [ "$ddd" ]; then	# REMOVE this block until 2019/7/1
    1.88 +    rm -f tmp/sql; cat $sqlfile >> tmp/sql
    1.89 +    err "----- `gdate +%FT%T.%3N` ------------555555aaaaa"
    1.90 +    # query ".read $sqlfile" > $tmpd/foo
    1.91 +    sqlite3 -header -cmd 'pragma foreign_keys=ON' $db ".read $sqlfile" > $tmpd/foo
    1.92 +    cp $tmpd/foo tmp/
    1.93 +    err "----- `gdate +%FT%T.%3N` ------------555555"
    1.94 +    ## $ddd LINE exists at the end of this function
    1.95 +  fi
    1.96 +  printf '.mode list\n.header 0\n' >> $sqlfile
    1.97    cat<<EOF | sed "s,\(<TR><TD>\)\([1-9][0-9]*\)\(#[0-9a-fxs]*\)*</TD>,\1$elink$dvlink</TD>," | dt_rowhack
    1.98  <div> <!-- for folding by check button (s4-funcs.sh:dumptable()) -->
    1.99  <div class="dumptable">
   1.100  <table class="b$dt_class">
   1.101 -`sq -header -cmd ".mode $1" $db ".read $sqlfile"`
   1.102 +`query ".read $sqlfile"`
   1.103  </table>
   1.104  </div> <!-- dumptable -->
   1.105  </div> <!-- for folding by check button (s4-funcs.sh:dumptable()) -->
   1.106  EOF
   1.107 +### `query ".read $sqlfile"`
   1.108 +### `sq -header -cmd ".mode $1" $db ".read $sqlfile"`
   1.109 +
   1.110 +  ## REMOVE THIS!
   1.111 +  [ "$ddd" ] && err "----- `gdate +%FT%T.%3N` ------------666666"
   1.112  }
   1.113  
   1.114  par2table() (