From: epg <> Date: Wed, 18 Jan 2006 21:25:45 +0000 (+0000) Subject: This 35k message folder at work is getting burdensome. minc was X-Git-Url: https://diplodocus.org/git/minc/commitdiff_plain/aaa6b4389ba09686e63242ab989f424e54ab1941 This 35k message folder at work is getting burdensome. minc was reading that entire folder everytime it stored a message there! Twice because mark(1) does it too. The first is my fault, the second mh's. I still haven't gone through mh to get rid of unnecessary readdirs, so work around the problem here. (get_highest_msgnum): Only read a directory once, saving the highest message number and incrementing it on each call. (mark): New function to add a message to a sequence. (store_message): Use mark instead of running mark(1). --- diff --git a/minc b/minc index cbf2996..8ac7af2 100755 --- a/minc +++ b/minc @@ -303,6 +303,7 @@ sub getfiles { return @result; } +my %msgnum_cache; sub get_highest_msgnum { my $mhfolder = shift; my $dir; @@ -310,6 +311,10 @@ sub get_highest_msgnum { my $highest; my $msgnum; + if (defined($msgnum_cache{$mhfolder})) { + return $msgnum_cache{$mhfolder}++; + } + $dir = "$mh/$mhfolder"; if (not opendir(DIR, $dir)) { die("opendir($dir): $!"); @@ -335,7 +340,36 @@ sub get_highest_msgnum { } } - return $highest; + return $msgnum_cache{$mhfolder} = $highest; +} + +sub mark { + my $folder = shift; + my $msgnum = shift; + my $seq = shift; + my $fn = "$mh/$folder/.mh_sequences"; + my $fh; + my @sequences; + + if (not open($fh, $fn)) { + $!{ENOENT} or die("open($fn): $!"); + } else { + @sequences = <$fh>; + chomp(@sequences); + } + + my $marked = 0; + open($fh, '>', $fn) or die("open(>$fn): $!"); + for $_ (@sequences) { + if (/^$seq: /) { + print($fh "$_ $msgnum\n"); + $marked = 1; + } else { + print($fh "$_\n"); + } + } + $marked or print($fh "$seq: $msgnum\n"); + close($fh) or die("close(>$fn): $!"); } sub store_message { @@ -412,15 +446,7 @@ sub store_message { if ($mhfolder eq 'SPAM') { push(@SPAM, $msgnum); } else { - $status = system('mark', "+$mhfolder", "$msgnum", '-sequence', - 'unseen', '-add'); - # XXX need to handle signalled and stopped, and print - # the exit code or signal number. - if (not WIFEXITED($status)) { - die("Failed to run mark"); - } elsif (WEXITSTATUS($status) != 0) { - die("Failed to mark message unseen."); - } + mark($mhfolder, $msgnum, 'unseen'); } }