From 49607b72d147c027ee19e663ee2313b1c7849cdc Mon Sep 17 00:00:00 2001 From: Jason Harvey Date: Thu, 16 Aug 2012 19:21:40 -0700 Subject: [PATCH] Add a memoized method of get_count, and use it by default. --- r2/r2/models/account.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index 4bdc987af..bcab96117 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -820,5 +820,10 @@ class AccountsActiveBySR(tdb_cassandra.View): {account._id36: ''}) @classmethod - def get_count(cls, sr): - return cls._cf.get_count(sr._id36) + def get_count(cls, sr, cached=True): + return cls.get_count_cached(sr._id36, _update=not cached) + + @classmethod + @memoize('accounts_active', time=60) + def get_count_cached(cls, sr_id): + return cls._cf.get_count(sr_id)