aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-11-20 01:36:40 +0000
committerRob Austein <sra@hactrn.net>2007-11-20 01:36:40 +0000
commit981f2073cc521942f6d4d2cdd0e370d57376437a (patch)
treeb9e17624f16d76451c56648dfb2e2b4f159c056d
parent9677b119c4c832f479ff56abe68fd26eb5717ad3 (diff)
Make better use of the object cache.
svn path=/scripts/rpki/sql.py; revision=1334
-rw-r--r--scripts/rpki/sql.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/rpki/sql.py b/scripts/rpki/sql.py
index c1681bd7..20ffe1dd 100644
--- a/scripts/rpki/sql.py
+++ b/scripts/rpki/sql.py
@@ -68,8 +68,16 @@ class sql_persistant(object):
@classmethod
def sql_fetch(cls, gctx, id):
- """Fetch one object from SQL, based on its primary key."""
- return cls.sql_fetch_where1(gctx, "%s = %s" % (cls.sql_template.index, id))
+ """Fetch one object from SQL, based on its primary key. Since in
+ this one case we know that the primary index is also the cache
+ key, we check for a cache hit directly in the hope of bypassing the
+ SQL lookup entirely.
+ """
+ key = (cls, id)
+ if key in sql_cache:
+ return sql_cache[key]
+ else:
+ return cls.sql_fetch_where1(gctx, "%s = %s" % (cls.sql_template.index, id))
@classmethod
def sql_fetch_where1(cls, gctx, where):