summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/MaildirIndexer/Index/ByAddresses.rakumod14
-rw-r--r--lib/MaildirIndexer/LogTimelineSchema.rakumod2
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod
index b2127de..0b77d15 100644
--- a/lib/MaildirIndexer/Index/ByAddresses.rakumod
+++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod
@@ -16,10 +16,14 @@ has Numeric %!p-address-given-mailbox;
has Int $!total-count;
has Numeric %!cached-p-given-mailbox;
-has Instant $!last-cached-at .= from-posix(0);
+has Supplier $!update-cache .= new;
constant $NOT-ZERO = 1e-15;
+submethod TWEAK() {
+ $!update-cache.Supply.stable(10).tap({ self.do-update-cache() });
+}
+
method dump() {
}
@@ -42,8 +46,11 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
}
}
- # update the cache every 10 seconds
- if ((now - $!last-cached-at) > 10) {
+ $!update-cache.emit(Any);
+}
+
+submethod do-update-cache() {
+ MaildirIndexer::LogTimelineSchema::Index::Cache.log: {
for $!count-by-mailbox.keys -> Str $mailbox {
my Numeric $p = $!count-by-mailbox{$mailbox} / $!total-count;
@@ -54,7 +61,6 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
%!cached-p-given-mailbox{$mailbox} = $p;
}
- $!last-cached-at = now;
}
}
diff --git a/lib/MaildirIndexer/LogTimelineSchema.rakumod b/lib/MaildirIndexer/LogTimelineSchema.rakumod
index ea0d2fc..1e95e65 100644
--- a/lib/MaildirIndexer/LogTimelineSchema.rakumod
+++ b/lib/MaildirIndexer/LogTimelineSchema.rakumod
@@ -20,3 +20,5 @@ class Index::Rm does Log::Timeline::Task['MaildirIndexer','Index','rm path'] { }
class Index::Find does Log::Timeline::Task['MaildirIndexer','Index','finding mailbox'] { };
class Server::Serve does Log::Timeline::Task['MaildirIndexer','Server','serving a request'] { };
+
+class Index::Cache does Log::Timeline::Task['MaildirIndexer','Index','update cache'] { };