diff options
author | Rob Austein <sra@hactrn.net> | 2007-11-20 01:36:40 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-11-20 01:36:40 +0000 |
commit | 981f2073cc521942f6d4d2cdd0e370d57376437a (patch) | |
tree | b9e17624f16d76451c56648dfb2e2b4f159c056d /scripts | |
parent | 9677b119c4c832f479ff56abe68fd26eb5717ad3 (diff) |
Make better use of the object cache.
svn path=/scripts/rpki/sql.py; revision=1334
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rpki/sql.py | 12 |
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): |