Speed improvements
This commit is contained in:
parent
0927f955e4
commit
cfe5d42e5d
92
t.sh
92
t.sh
|
@ -1,9 +1,16 @@
|
||||||
#!/bin/bash
|
#!/opt/homebrew/bin/bash
|
||||||
#set -x
|
#set -x
|
||||||
|
|
||||||
trap "exit 1" TERM
|
trap "exit 1" TERM
|
||||||
export MYPID=$$
|
export MYPID=$$
|
||||||
|
|
||||||
|
if [[ ${BASH_VERSION:0:1} == 5 ]]; then
|
||||||
|
b5=1
|
||||||
|
declare -A idmap
|
||||||
|
else
|
||||||
|
b5=0
|
||||||
|
fi
|
||||||
|
|
||||||
. ${HOME}/code/bashtools/bashtools.sh
|
. ${HOME}/code/bashtools/bashtools.sh
|
||||||
if [[ -z $HAVE_BASHTOOLS ]]; then
|
if [[ -z $HAVE_BASHTOOLS ]]; then
|
||||||
echo "ERROR: bashtools not installed download from https://git.nethack.net/rob/bashtools" >/dev/stderr
|
echo "ERROR: bashtools not installed download from https://git.nethack.net/rob/bashtools" >/dev/stderr
|
||||||
|
@ -23,6 +30,20 @@ TOPTITLE="\033[44;1m"
|
||||||
LEFTTITLE="\033[31;1m"
|
LEFTTITLE="\033[31;1m"
|
||||||
FOLDBG="$BOLDD"
|
FOLDBG="$BOLDD"
|
||||||
|
|
||||||
|
|
||||||
|
function genidx() {
|
||||||
|
local idxname=$1 x
|
||||||
|
shift
|
||||||
|
local -a vals=("$@")
|
||||||
|
unset ${idxname}
|
||||||
|
declare -g -A ${idxname}
|
||||||
|
for x in "${!vals[@]}"; do
|
||||||
|
#echo "setting ${idxname}[${vals[$x]}] to $x" >/dev/stderr
|
||||||
|
eval ${idxname}["${vals[$x]}"]=$x
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function die() {
|
function die() {
|
||||||
kill -s TERM $MYPID
|
kill -s TERM $MYPID
|
||||||
}
|
}
|
||||||
|
@ -51,6 +72,7 @@ function usage() {
|
||||||
echo " -c Select calendar to use (use '$0 showcals' to list)"
|
echo " -c Select calendar to use (use '$0 showcals' to list)"
|
||||||
echo " -f Assume 'yes' to all questions."
|
echo " -f Assume 'yes' to all questions."
|
||||||
echo " -l xx Specify name of local vdirsyncer storage name (default: $DEFAULT_VDS_LOCAL)"
|
echo " -l xx Specify name of local vdirsyncer storage name (default: $DEFAULT_VDS_LOCAL)"
|
||||||
|
echo " -m Maintenance mode - find and fix bad idmapping entries, then exit."
|
||||||
echo " -p Enable profiling"
|
echo " -p Enable profiling"
|
||||||
echo " -r xx Specify name of remote vdirsyncer storage name (default: $DEFAULT_VDS_REMOTE)"
|
echo " -r xx Specify name of remote vdirsyncer storage name (default: $DEFAULT_VDS_REMOTE)"
|
||||||
echo " -s Auto-sync with server when complete."
|
echo " -s Auto-sync with server when complete."
|
||||||
|
@ -91,12 +113,20 @@ function getuid_witherror() { # [noun]
|
||||||
|
|
||||||
function getid() {
|
function getid() {
|
||||||
local res="" id
|
local res="" id
|
||||||
|
if [[ $b5 ]]; then
|
||||||
|
if [[ "${i_idmap[$1]}" ]]; then
|
||||||
|
echo "${i_idmap[$1]}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
else
|
||||||
for id in ${!idmap[@]}; do
|
for id in ${!idmap[@]}; do
|
||||||
if [[ ${idmap[$id]} == $1 ]]; then
|
if [[ ${idmap[$id]} == $1 ]]; then
|
||||||
echo "$id"
|
echo "$id"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +149,11 @@ function loadids() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
profile "start"
|
profile "start"
|
||||||
|
|
||||||
|
# check for duplicate id mappings
|
||||||
|
sort -o $f -t: -k1,1 --stable --unique "$idfile"
|
||||||
|
profile "finished removing dupes"
|
||||||
|
|
||||||
max=0
|
max=0
|
||||||
while read LINE; do
|
while read LINE; do
|
||||||
uid=${LINE%:*}
|
uid=${LINE%:*}
|
||||||
|
@ -126,6 +161,7 @@ function loadids() {
|
||||||
#uid=$(echo "$LINE" | sed 's/:.*$//g')
|
#uid=$(echo "$LINE" | sed 's/:.*$//g')
|
||||||
#id=$(echo "$LINE" | sed 's/^.*://g')
|
#id=$(echo "$LINE" | sed 's/^.*://g')
|
||||||
idmap[$id]=$uid
|
idmap[$id]=$uid
|
||||||
|
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||||
if [[ -z $uid || -z $id ]]; then
|
if [[ -z $uid || -z $id ]]; then
|
||||||
error "invalid idmapping line: '$LINE'"
|
error "invalid idmapping line: '$LINE'"
|
||||||
profile "end"
|
profile "end"
|
||||||
|
@ -137,6 +173,7 @@ function loadids() {
|
||||||
nextid=$((max + 1))
|
nextid=$((max + 1))
|
||||||
profile "end"
|
profile "end"
|
||||||
dblog "got $count IDs from $idfile"
|
dblog "got $count IDs from $idfile"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +209,8 @@ function dumpids() {
|
||||||
|
|
||||||
function loadtasks() {
|
function loadtasks() {
|
||||||
local f ess x thislev par parid show thissum thisdesc
|
local f ess x thislev par parid show thissum thisdesc
|
||||||
local verbose=0
|
local verbose=0 nextid2=1
|
||||||
|
|
||||||
profile "start"
|
profile "start"
|
||||||
maxid=-1
|
maxid=-1
|
||||||
maxindent=-1
|
maxindent=-1
|
||||||
|
@ -190,8 +228,18 @@ function loadtasks() {
|
||||||
numwid=${#maxid}
|
numwid=${#maxid}
|
||||||
profile "finished loadtask calls"
|
profile "finished loadtask calls"
|
||||||
|
|
||||||
|
# ---ooooo implement get_next_id()
|
||||||
|
# minid=$( echo "${taskid[@]}" | tr ' ' '\n' | sort -nr | tail -1)
|
||||||
|
# if [[ $minid -lt $nextid ]]; then
|
||||||
|
# nextid2=1
|
||||||
|
# while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do
|
||||||
|
# nextid2=$((nextid2 + 1))
|
||||||
|
# done
|
||||||
|
# nextid=$nextid2
|
||||||
|
# fi
|
||||||
|
|
||||||
dblog "Calculating max indent level"
|
dblog "Calculating max indent level"
|
||||||
# figure out max indent level
|
# figure out max indent level and next id
|
||||||
for x in ${!taskuid[@]}; do
|
for x in ${!taskuid[@]}; do
|
||||||
show=1
|
show=1
|
||||||
par=${taskparent[$x]}
|
par=${taskparent[$x]}
|
||||||
|
@ -218,6 +266,7 @@ function loadtasks() {
|
||||||
|
|
||||||
[[ $ntasks -eq 1 ]] && ess="" || ess="s"
|
[[ $ntasks -eq 1 ]] && ess="" || ess="s"
|
||||||
[[ $verbose -eq 1 ]] && inform "Finished loading $ntasks task$ess."
|
[[ $verbose -eq 1 ]] && inform "Finished loading $ntasks task$ess."
|
||||||
|
|
||||||
dblog "Finished loading $ntasks task$ess."
|
dblog "Finished loading $ntasks task$ess."
|
||||||
profile "end"
|
profile "end"
|
||||||
return 0
|
return 0
|
||||||
|
@ -286,6 +335,7 @@ dblog "process token '${tok[$i]}'"
|
||||||
if [[ -z $id ]]; then
|
if [[ -z $id ]]; then
|
||||||
id=$nextid
|
id=$nextid
|
||||||
idmap[$nextid]=$uid
|
idmap[$nextid]=$uid
|
||||||
|
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||||
nextid=$((nextid + 1))
|
nextid=$((nextid + 1))
|
||||||
needsave=1
|
needsave=1
|
||||||
fi
|
fi
|
||||||
|
@ -1681,10 +1731,14 @@ AUTOSYNC=0
|
||||||
CALID=$(cat "$confdir/defaultcal")
|
CALID=$(cat "$confdir/defaultcal")
|
||||||
WANTSORT=0
|
WANTSORT=0
|
||||||
USEPAGER=1
|
USEPAGER=1
|
||||||
|
MAINTMODE=0
|
||||||
|
|
||||||
ARGS="fhic:dnsStyl:r:p"
|
ARGS="fhic:dmnsStyl:r:p"
|
||||||
while getopts "$ARGS" i; do
|
while getopts "$ARGS" i; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
|
m)
|
||||||
|
MAINTMODE=1
|
||||||
|
;;
|
||||||
h)
|
h)
|
||||||
usage;
|
usage;
|
||||||
exit 1;
|
exit 1;
|
||||||
|
@ -1795,6 +1849,36 @@ loadids || exit 1
|
||||||
loadtasks || exit 1
|
loadtasks || exit 1
|
||||||
ok
|
ok
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $MAINTMODE -eq 1 ]]; then
|
||||||
|
# check for id mappings with missing tasks
|
||||||
|
notify "Checking ID mappings"
|
||||||
|
nbad=0
|
||||||
|
for x in ${!idmap[@]}; do
|
||||||
|
if (! IFS=$'\n'; echo "${taskid[*]}" ) | grep -qFx "${idmap[$x]}" ; then
|
||||||
|
warn "idmap has missing task ${idmap[$x]}"
|
||||||
|
tofix="$tofix $x "
|
||||||
|
nbad=$(( nbad + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[[ $nbad -ge 1 ]] && partial "$nbad need fixing" || ok
|
||||||
|
|
||||||
|
if [[ -n $tofix ]]; then
|
||||||
|
notify "Fixing ID mappings for missing tasks"
|
||||||
|
for x in $tofix; do
|
||||||
|
[[ $b5 -eq 1 ]] && unset i_idmap[${idmap[$x]}];
|
||||||
|
unset idmap[$x]
|
||||||
|
done
|
||||||
|
ok
|
||||||
|
idfilebackup="$idfile.bak.$(date +%Y%m%d%H%M%S)"
|
||||||
|
inform "idmap backup is in $idfilebackup"
|
||||||
|
cp -a "$idfile" "$idfilebackup"
|
||||||
|
saveids
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
[[ $TESTMODE -eq 1 ]] && exit 1
|
[[ $TESTMODE -eq 1 ]] && exit 1
|
||||||
|
|
||||||
[[ $needsave -eq 1 ]] && saveids
|
[[ $needsave -eq 1 ]] && saveids
|
||||||
|
|
Loading…
Reference in New Issue