Speed improvements
This commit is contained in:
parent
0927f955e4
commit
cfe5d42e5d
100
t.sh
100
t.sh
|
@ -1,9 +1,16 @@
|
|||
#!/bin/bash
|
||||
#!/opt/homebrew/bin/bash
|
||||
#set -x
|
||||
|
||||
trap "exit 1" TERM
|
||||
export MYPID=$$
|
||||
|
||||
if [[ ${BASH_VERSION:0:1} == 5 ]]; then
|
||||
b5=1
|
||||
declare -A idmap
|
||||
else
|
||||
b5=0
|
||||
fi
|
||||
|
||||
. ${HOME}/code/bashtools/bashtools.sh
|
||||
if [[ -z $HAVE_BASHTOOLS ]]; then
|
||||
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"
|
||||
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() {
|
||||
kill -s TERM $MYPID
|
||||
}
|
||||
|
@ -51,6 +72,7 @@ function usage() {
|
|||
echo " -c Select calendar to use (use '$0 showcals' to list)"
|
||||
echo " -f Assume 'yes' to all questions."
|
||||
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 " -r xx Specify name of remote vdirsyncer storage name (default: $DEFAULT_VDS_REMOTE)"
|
||||
echo " -s Auto-sync with server when complete."
|
||||
|
@ -91,12 +113,20 @@ function getuid_witherror() { # [noun]
|
|||
|
||||
function getid() {
|
||||
local res="" id
|
||||
for id in ${!idmap[@]}; do
|
||||
if [[ ${idmap[$id]} == $1 ]]; then
|
||||
echo "$id"
|
||||
if [[ $b5 ]]; then
|
||||
if [[ "${i_idmap[$1]}" ]]; then
|
||||
echo "${i_idmap[$1]}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
else
|
||||
for id in ${!idmap[@]}; do
|
||||
if [[ ${idmap[$id]} == $1 ]]; then
|
||||
echo "$id"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -119,6 +149,11 @@ function loadids() {
|
|||
return 1
|
||||
fi
|
||||
profile "start"
|
||||
|
||||
# check for duplicate id mappings
|
||||
sort -o $f -t: -k1,1 --stable --unique "$idfile"
|
||||
profile "finished removing dupes"
|
||||
|
||||
max=0
|
||||
while read LINE; do
|
||||
uid=${LINE%:*}
|
||||
|
@ -126,6 +161,7 @@ function loadids() {
|
|||
#uid=$(echo "$LINE" | sed 's/:.*$//g')
|
||||
#id=$(echo "$LINE" | sed 's/^.*://g')
|
||||
idmap[$id]=$uid
|
||||
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||
if [[ -z $uid || -z $id ]]; then
|
||||
error "invalid idmapping line: '$LINE'"
|
||||
profile "end"
|
||||
|
@ -137,6 +173,7 @@ function loadids() {
|
|||
nextid=$((max + 1))
|
||||
profile "end"
|
||||
dblog "got $count IDs from $idfile"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -172,7 +209,8 @@ function dumpids() {
|
|||
|
||||
function loadtasks() {
|
||||
local f ess x thislev par parid show thissum thisdesc
|
||||
local verbose=0
|
||||
local verbose=0 nextid2=1
|
||||
|
||||
profile "start"
|
||||
maxid=-1
|
||||
maxindent=-1
|
||||
|
@ -190,8 +228,18 @@ function loadtasks() {
|
|||
numwid=${#maxid}
|
||||
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"
|
||||
# figure out max indent level
|
||||
# figure out max indent level and next id
|
||||
for x in ${!taskuid[@]}; do
|
||||
show=1
|
||||
par=${taskparent[$x]}
|
||||
|
@ -218,6 +266,7 @@ function loadtasks() {
|
|||
|
||||
[[ $ntasks -eq 1 ]] && ess="" || ess="s"
|
||||
[[ $verbose -eq 1 ]] && inform "Finished loading $ntasks task$ess."
|
||||
|
||||
dblog "Finished loading $ntasks task$ess."
|
||||
profile "end"
|
||||
return 0
|
||||
|
@ -286,6 +335,7 @@ dblog "process token '${tok[$i]}'"
|
|||
if [[ -z $id ]]; then
|
||||
id=$nextid
|
||||
idmap[$nextid]=$uid
|
||||
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||
nextid=$((nextid + 1))
|
||||
needsave=1
|
||||
fi
|
||||
|
@ -1681,10 +1731,14 @@ AUTOSYNC=0
|
|||
CALID=$(cat "$confdir/defaultcal")
|
||||
WANTSORT=0
|
||||
USEPAGER=1
|
||||
MAINTMODE=0
|
||||
|
||||
ARGS="fhic:dnsStyl:r:p"
|
||||
ARGS="fhic:dmnsStyl:r:p"
|
||||
while getopts "$ARGS" i; do
|
||||
case "$i" in
|
||||
m)
|
||||
MAINTMODE=1
|
||||
;;
|
||||
h)
|
||||
usage;
|
||||
exit 1;
|
||||
|
@ -1795,6 +1849,36 @@ loadids || exit 1
|
|||
loadtasks || exit 1
|
||||
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
|
||||
|
||||
[[ $needsave -eq 1 ]] && saveids
|
||||
|
|
Loading…
Reference in New Issue