From: Colin Watson Date: Sun, 31 May 2009 04:34:13 +0000 (+0000) Subject: speed up use of sa-learn X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=commitdiff_plain;h=671daef7e5083b48b55fa799c40b9e6332693494 speed up use of sa-learn --- diff --git a/sa-learn-cache b/sa-learn-cache new file mode 100755 index 0000000..b51c4e7 --- /dev/null +++ b/sa-learn-cache @@ -0,0 +1,40 @@ +#! /bin/sh +# Depends: chiark-utils-bin +set -e + +DIR="$HOME/tmp/sa-learn-cache" + +LOCKED=false +if [ "$1" = --locked ]; then + LOCKED=: + shift +fi + +if [ "$1" = --spam ]; then + CACHE="$DIR/spam" +elif [ "$1" = --ham ]; then + CACHE="$DIR/ham" +else + echo "don't know how to handle anything other than --spam or --ham" >&2 + exit 1 +fi +LOCK="$CACHE.lock" + +mkdir -p "$DIR" + +if ! $LOCKED; then + exec with-lock-ex -w "$LOCK" "$0" --locked "$@" +else + if [ -e "$CACHE" ]; then + SIZE="$(stat -c %s "$CACHE")" + else + SIZE=0 + fi + cat >> "$CACHE" + if [ "$SIZE" -gt 4194304 ]; then + sa-learn --mbox --no-sync "$@" < "$CACHE" + rm -f "$CACHE" + fi +fi + +exit 0