From 89ed77e5d87574b9eb391a9c984f56138a0d0767 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 16 Mar 2020 15:20:33 +0000 Subject: actually working cache updating in ByAddresses --- lib/MaildirIndexer/Index/ByAddresses.rakumod | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/MaildirIndexer/Index/ByAddresses.rakumod') 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; } } -- cgit v1.2.3