s4

changeset 887:8229c75e9f94

Ensure user_s update
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 22 Dec 2020 08:24:23 +0900
parents 99187e4ad69b
children 7ca1f11ab5e8
files s4-funcs.sh s4-world.sh
diffstat 2 files changed, 18 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Thu Dec 17 07:56:38 2020 +0900
     1.2 +++ b/s4-funcs.sh	Tue Dec 22 08:24:23 2020 +0900
     1.3 @@ -1411,6 +1411,15 @@
     1.4  mypwhash() {
     1.5    mycrypt "`cat`" `genrandom 5`
     1.6  }
     1.7 +flag_profupdate() {
     1.8 +  # XXX:	Sorry to use undeclared column in user.def
     1.9 +  #		This is useful to mitigate account sync load
    1.10 +  query <<-EOF
    1.11 +	REPLACE INTO user_s(name, key, type, val)
    1.12 +	VALUES('$user', 'profupdate', 'string', datetime('now', 'localtime'));
    1.13 +	EOF
    1.14 +  touch $userupdateflag
    1.15 +}
    1.16  wasureta() {
    1.17    user=$1
    1.18    if ! checkdomain $user; then
    1.19 @@ -4247,15 +4256,7 @@
    1.20  	RELEASE SAVEPOINT pa2table_insert;
    1.21  	EOF
    1.22    rc=$?
    1.23 -  if [ $rc -eq 0 -a x"$tbl" = x"user" ]; then
    1.24 -    # XXX:	Sorry to use undeclared column in user.def
    1.25 -    #		This is useful to mitigate account sync load
    1.26 -    query <<-EOF
    1.27 -	REPLACE INTO user_s(name, key, type, val)
    1.28 -	VALUES('$user', 'profupdate', 'string', datetime('now', 'localtime'));
    1.29 -	EOF
    1.30 -    touch $userupdateflag
    1.31 -  fi
    1.32 +  [ $rc -eq 0 -a x"$tbl" = x"user" ] && flag_profupdate
    1.33    ## err "Table:$tbl update done "
    1.34    return $rc
    1.35  )
     2.1 --- a/s4-world.sh	Thu Dec 17 07:56:38 2020 +0900
     2.2 +++ b/s4-world.sh	Tue Dec 22 08:24:23 2020 +0900
     2.3 @@ -78,6 +78,7 @@
     2.4      fi
     2.5    fi
     2.6    err "`gdate +%S.%3N` Starting account synchronization"
     2.7 +  SYNC_M=1
     2.8  
     2.9    prevsync=`tail -1 $syncflag|colrm 20`	# 2020-06-21 12:30:00 = 19cols
    2.10    syncall=${db%.*}.syncall
    2.11 @@ -96,6 +97,7 @@
    2.12        else
    2.13  	err synccond canceled for user_m
    2.14  	SYNCCOND="WHERE NULL"
    2.15 +	SYNC_M=
    2.16        fi
    2.17        err "Touch $syncall (owner=`id -un`) to update all user_m."
    2.18        ;;
    2.19 @@ -114,23 +116,24 @@
    2.20  DELETE FROM main.user_s WHERE rowid NOT IN (SELECT rowid FROM m.user_s);
    2.21  REPLACE INTO main.user_s(rowid, name, key, type, val, bin)
    2.22  	SELECT rowid,* FROM m.user_s;
    2.23 +${SYNC_M:+
    2.24  DELETE FROM main.user_m WHERE rowid NOT IN (SELECT rowid FROM m.user_m);
    2.25  REPLACE INTO main.user_m(rowid, name, key, type, val, bin)
    2.26  	SELECT rowid,* FROM m.user_m    $SYNCCOND
    2.27  	   EXCEPT
    2.28  	SELECT rowid,* FROM main.user_m $SYNCCOND
    2.29 -	;
    2.30 +	;} /* SYNC_M closed here */
    2.31  END;
    2.32  
    2.33  /* Compare user tables */
    2.34  WITH master AS (
    2.35    SELECT p.rowid,* FROM m.user p
    2.36 -  	 NATURAL LEFT JOIN m.user_s
    2.37 -	 NATURAL LEFT JOIN m.user_m
    2.38 +  			 NATURAL LEFT JOIN m.user_s
    2.39 +	 ${SYNC_M:+	 NATURAL LEFT JOIN m.user_m}
    2.40  ), thisworld AS (
    2.41    SELECT p.rowid,* FROM user p
    2.42 -  	 NATURAL LEFT JOIN user_s
    2.43 - 	 NATURAL LEFT JOIN user_m
    2.44 +		  	NATURAL LEFT JOIN user_s
    2.45 + 	 ${SYNC_M:+	NATURAL LEFT JOIN user_m}
    2.46  ), m_a AS (
    2.47    SELECT * FROM master EXCEPT SELECT * FROM thisworld
    2.48  ), a_m AS (