summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Index/ByAddresses.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MaildirIndexer/Index/ByAddresses.rakumod')
-rw-r--r--lib/MaildirIndexer/Index/ByAddresses.rakumod14
1 files changed, 10 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;
}
}