diff options
author | dakkar <dakkar@thenautilus.net> | 2020-03-16 15:20:33 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2020-03-16 15:34:19 +0000 |
commit | 89ed77e5d87574b9eb391a9c984f56138a0d0767 (patch) | |
tree | 5bad2ea1d18d82228602a96ab49966cfb3f4dc11 /lib/MaildirIndexer/Index/ByAddresses.rakumod | |
parent | more async! (diff) | |
download | MaildirIndexer-89ed77e5d87574b9eb391a9c984f56138a0d0767.tar.gz MaildirIndexer-89ed77e5d87574b9eb391a9c984f56138a0d0767.tar.bz2 MaildirIndexer-89ed77e5d87574b9eb391a9c984f56138a0d0767.zip |
actually working cache updating in ByAddresses
Diffstat (limited to 'lib/MaildirIndexer/Index/ByAddresses.rakumod')
-rw-r--r-- | lib/MaildirIndexer/Index/ByAddresses.rakumod | 14 |
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; } } |