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 | |
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')
-rw-r--r-- | lib/MaildirIndexer/Index/ByAddresses.rakumod | 14 | ||||
-rw-r--r-- | lib/MaildirIndexer/LogTimelineSchema.rakumod | 2 |
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'] { }; |