Skip to content

Commit

Permalink
add caching for objectids
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Jul 14, 2011
1 parent e5d06ad commit 6ec2f89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 14 additions & 3 deletions master/buildbot/db/state.py
Expand Up @@ -43,6 +43,17 @@ def getObjectId(self, name, class_name):
@param class_name: object class name
@returns: the objectid, via a Deferred.
"""
# defer to a cached metho that only takes one parameter (a tuple)
return self._getObjectId((name, class_name)
).addCallback(lambda list : list[0])

@base.cached('objectids')
def _getObjectId(self, name_class_name_tuple):
"""
Cache-compatible implementation of L{_getObjectId}, taking a single
parameter and returning a weakref-able value (a list).
"""
name, class_name = name_class_name_tuple
def thd(conn):
objects_tbl = self.db.model.objects

Expand All @@ -67,18 +78,18 @@ def insert():
# then try selecting again. We include an invocation of a hook
# method to allow tests to exercise this particular behavior
try:
return select()
return [ select() ]
except _IdNotFoundError:
pass

self._test_timing_hook(conn)

try:
return insert()
return [ insert() ]
except (sqlalchemy.exc.IntegrityError, sqlalchemy.exc.ProgrammingError):
pass

return select()
return [ select() ]

return self.db.pool.do(thd)

Expand Down
7 changes: 7 additions & 0 deletions master/docs/cfg-global.texinfo
Expand Up @@ -326,6 +326,13 @@ be similar to the number BuildRequesets.
The number of rows from the @code{sourcestamps} table to cache in memory. This
value should be similar to the value for @code{SourceStamps}.

@item objectids

The number of object IDs - a means to correlate an object in the Buildbot
configuration with an identity in the database - to cache. In this version,
object IDs are not looked up often during runtime, so a relatively low value
such as 10 is fine.

@end enumerate

The @emph{global} @code{buildCacheSize} parameter gives the number of builds
Expand Down

0 comments on commit 6ec2f89

Please sign in to comment.