summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Misc.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-29 18:27:52 +0100
committerYorhel <git@yorhel.nl>2008-11-29 18:27:52 +0100
commit9d2976410afbc101574d7dfabbdb70b68bf8e419 (patch)
treedf33cfd85f39b4edba6a36e3866b053206a6adc9 /lib/VNDB/DB/Misc.pm
parent2fccaa6db5ca4bf5e2c9f50b810ac24dc14c500e (diff)
Caching the global database statistics
Because I can't say no to a performance increase of 4 to 7ms for -every- pageview! Makes use of postgresql triggers and stored procedures.
Diffstat (limited to 'lib/VNDB/DB/Misc.pm')
-rw-r--r--lib/VNDB/DB/Misc.pm13
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index 5b810583..a58534c6 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -10,18 +10,13 @@ our @EXPORT = qw|
|;
-# Arguments: array of elements to get stats from, options:
-# vn, producers, releases, users, threads, posts
-# Returns: hashref, key = element, value = number of entries
-# TODO: caching, see http://www.varlena.com/GeneralBits/120.php
+# Returns: hashref, key = section, value = number of (visible) entries
+# Sections: vn, producers, releases, users, threads, posts
sub dbStats {
my $s = shift;
return { map {
- $_ => $s->dbRow('SELECT COUNT(*) as cnt FROM !s !W',
- /posts/ ? 'threads_posts' : $_,
- /producers|vn|releases|threads|posts/ ? { 'hidden = ?' => 0 } : {}
- )->{cnt} - (/users/ ? 1 : 0);
- } @_ };
+ $_->{section} eq 'threads_posts' ? 'posts' : $_->{section}, $_->{count}
+ } @{$s->dbAll('SELECT * FROM stats_cache')}};
}