s4

changeset 281:dd8629e6d67e

Ugly workaround to speed up count-new
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 02 Aug 2016 22:09:06 +0859
parents 2d2d32a9bb80
children e6c1cbe4ffcc
files s4-funcs.sh
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Tue Aug 02 14:43:20 2016 +0859
     1.2 +++ b/s4-funcs.sh	Tue Aug 02 22:09:06 2016 +0859
     1.3 @@ -2574,11 +2574,14 @@
     1.4    if [ -n "$DT_CHLD" ]; then
     1.5      _t=${DT_CHLD%:*} _i=${DT_CHLD#*:}
     1.6      cntall="(select count($_i) from $_t where $_i=a.id)"
     1.7 +    # XXX: Dirty workaround for slow subquery of acclog
     1.8 +    presql="CREATE TEMPORARY TABLE IF NOT EXISTS myacclog AS
     1.9 +            SELECT * FROM acclog WHERE user='$user' and tbl='$2';"
    1.10      cntnew="(select count(val) from ${_t}_s where key='ctime' \
    1.11 -	and id in (select id from $_t where $_i=a.id) \
    1.12 -	and val > coalesce((select time from acclog where \
    1.13 -			    user='$user' and tbl='$2' and tblrowid=a.rowid),\
    1.14 -		    '1970-01-01'))"
    1.15 +        and id in (select id from $_t where $_i=a.id) \
    1.16 +        and val > coalesce((select time from myacclog where \
    1.17 +                            tblrowid=a.rowid),\
    1.18 +                    '1970-01-01'))"
    1.19      cnt="$cntnew as '新着', $cntall as '総数',"
    1.20      dt_class=" td2r td3r dumpblogs"
    1.21    fi
    1.22 @@ -2606,12 +2609,12 @@
    1.23  	max(case key when 'owner'
    1.24  	 then (SELECT gecos FROM gecoses WHERE name=val) END) as gecos
    1.25   from ${2}_s c group by $pk) b on a.$pk=b.$pk $4;"}
    1.26 -  err SQL=`echo "$sql"`
    1.27 +  err SQL="`echo \"$presql$sql\"|tr -d '\n'`"
    1.28    cat<<EOF | sed "s,\(<TR><TD>\)\([1-9][0-9]*\)\(#[0-9a-fxs]*\)*</TD>,\1$elink$dvlink</TD>,"
    1.29  <div> <!-- for folding by check button (s4-funcs.sh:dumptable()) -->
    1.30  <div class="dumptable">
    1.31  <table class="b$dt_class">
    1.32 -`sq -header -cmd ".mode $1" $db "$sql"`
    1.33 +`sq -header -cmd ".mode $1" $db "$presql$sql"`
    1.34  </table>
    1.35  </div> <!-- dumptable -->
    1.36  </div> <!-- for folding by check button (s4-funcs.sh:dumptable()) -->