increase speed heavily

This was possible by removing the step to tag mails in the inbox and move them directly instead; by removing a few unnecessary for loops; and interrupting the while loop if there is not even a thread to search in
This commit is contained in:
2018-07-04 09:26:14 +02:00
parent 3b366b4a17
commit 1f153edaec

View File

@@ -5,7 +5,7 @@
CURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) CURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DEBUG=false # use 'true' to echo verbose debug messages DEBUG=true # use 'true' to echo verbose debug messages
CSV="$CURDIR"/tag-list.csv # Table of tags/folders CSV="$CURDIR"/tag-list.csv # Table of tags/folders
MAILDIR="$HOME/Mails/FSFE" # Maildir MAILDIR="$HOME/Mails/FSFE" # Maildir
@@ -46,10 +46,10 @@ function debugmsg {
# Set date until when files are searched for, depending on current connection status # Set date until when files are searched for, depending on current connection status
if [ "${var_conn}" == "off" ]; then if [ "${var_conn}" == "off" ]; then
DATELIMIT="1d" DATELIMIT="1d"
logrun echo "Datelimit for search set to $DATELIMIT" echo "Datelimit for search set to $DATELIMIT"
else else
DATELIMIT="14d" DATELIMIT="14d"
logrun echo "Datelimit for search set to $DATELIMIT" echo "Datelimit for search set to $DATELIMIT"
fi fi
while read line; do while read line; do
@@ -85,34 +85,23 @@ while read line; do
# 1. Get thread ids of all entries with the searched tag # 1. Get thread ids of all entries with the searched tag
debugmsg "search for all threads tagged with $TAG" debugmsg "search for all threads tagged with $TAG"
THREADS=$(notmuch search --exclude=false tag:$TAG and date:${DATELIMIT}.. | cut -d" " -f1 | cut -d":" -f2) THREADS=$(notmuch search --exclude=false --output=threads tag:$TAG and date:${DATELIMIT}..)
if [[ -z $THREADS ]]; then debugmsg "Tag $TAG finished. No thread within ${DATELIMIT} found."; debugmsg ""; continue; fi
# 2. Get message ids of all messages in these threads # 2. Get message ids of all messages in these threads
debugmsg "search for all IDs of these threads" debugmsg "search for all IDs of these "$(echo "$THREADS" | wc -w)" threads"
MID= MID=$(notmuch search --output=messages --exclude=false $THREADS)
for t in $THREADS; do # MID consists of many something like "id:5XXX0CD1.305516@fsfe.org"
MID="$MID "$(notmuch search --output=messages --exclude=false thread:$t)
# MID consists of many something like "id:5XXX0CD1.305516@fsfe.org"
done
# 3. Tag all message ids of messages which are still in INBOX # 3. Mark all files of messages if they are still in INBOX
debugmsg "tag all these IDs if they are in INBOX:" $(echo "$MID" | wc -w) "files" debugmsg "mark all files of "$(echo "$MID" | wc -w)" IDs if they are in INBOX"
for m in $MID; do HITFILES=$(notmuch search --output=files --exclude=false "$MID" | grep "$MAILDIR/INBOX/")
if $(notmuch search --exclude=false --output=files "$m" | grep -q "$MAILDIR/INBOX/"); then
debugmsg "tag $m with $TAG"
logrun notmuch tag +"$TAG" -- "$m"
fi
done
# Search for these lone messages in INBOX
debugmsg "search for these messages which are still in INBOX"
HITFILES=$(notmuch search --output=files --exclude=false path:INBOX/** and tag:$TAG | grep "$MAILDIR/INBOX/")
fi fi
fi fi
# Move files to their destination folders # Move files to their destination folders
debugmsg "move the files of tag $TAG" debugmsg "move "$(echo "$HITFILES" | wc -w)" files of tag $TAG from INBOX"
for m in $HITFILES; do for m in $HITFILES; do
# Destination folder is derived from the current location # Destination folder is derived from the current location