[925] in BarnOwl Developers
[D-O-H] r912 - branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:11:12 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@MIT.EDU
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Fri, 1 Feb 2008 01:50:07 -0500 (EST)
Author: nelhage
Date: 2008-02-01 01:50:06 -0500 (Fri, 01 Feb 2008)
New Revision: 912
Modified:
branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm
Log:
* Cache the message list size in RAM
* Don't cache messages when we're doing a full message list traversal
Modified: branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm
===================================================================
--- branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm 2008-01-30 20:49:35 UTC (rev 911)
+++ branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm 2008-02-01 06:50:06 UTC (rev 912)
@@ -19,12 +19,15 @@
use JSON;
use POSIX qw(ctime);
use Cache::Memory;
+use Time::HiRes qw(time);
my $MESSAGES = 'messages';
my $message_fields = [qw(id msg_time protocol body direction)];
my $ATTRS = 'attributes';
my $attr_fields = [qw(message_id key value)];
+my $SIZE_KEY = '__size';
+
__PACKAGE__->mk_ro_accessors(qw(db cache));
__PACKAGE__->mk_accessors(qw(msg_iter attr_iter attr_lookahead _next_id deleted));
@@ -76,9 +79,14 @@
sub get_size {
my $self = shift;
- my $count = $self->db->query("SELECT COUNT(*) from $MESSAGES WHERE expunged='false'")
+ my $cnt;
+ if($cnt = $self->cache->get($SIZE_KEY)) {
+ return $cnt;
+ }
+ my $count = $self->db->query("SELECT COUNT(id) from $MESSAGES WHERE expunged='false'")
or die("Can't SELECT COUNT:" . $self->db->error);
- my $cnt = $count->fetch->[0];
+ $cnt = $count->fetch->[0];
+ $self->cache->set($SIZE_KEY => $cnt);
return $cnt;
}
@@ -149,7 +157,7 @@
}
$msg{deleted} = 1 if($self->deleted->{$msg{id}});
$msg = BarnOwl::Message->new(%msg);
- $self->cache->set($msg{id} => $msg);
+ # $self->cache->set($msg{id} => $msg);
return $msg;
}
@@ -159,7 +167,9 @@
my $msg;
my %msg;
+ my $start = time;
$msg = $self->cache->get($id);
+ BarnOwl::debug("cache-get($id): " . (time - $start));
if($msg) { return $msg; }
$msg = $self->db->select($MESSAGES, $message_fields, {id => $id})
@@ -178,6 +188,7 @@
$msg{deleted} = 1 if($self->deleted->{$msg{id}});
$msg = BarnOwl::Message->new(%msg);
$self->cache->set($id => $msg);
+ BarnOwl::debug("SQL-get($id): " . (time - $start));
return $msg;
}
@@ -205,6 +216,7 @@
or die($self->db->error);
}
$self->db->commit;
+ $self->cache->remove($SIZE_KEY);
}
sub expunge {