[LNT] r305723 - Refactor db startup code to have fewer DB round trips
Chris Matthews via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 19 10:58:16 PDT 2017
Author: cmatthews
Date: Mon Jun 19 12:58:16 2017
New Revision: 305723
URL: http://llvm.org/viewvc/llvm-project?rev=305723&view=rev
Log:
Refactor db startup code to have fewer DB round trips
When running on hosted DBs, there is a non-zero latency to queries. This
startup code was making queries more than it needed to. Replace 7 single
queries with 2 bulk queries, and then process more on client. Also
update failure paths to use fatal instead of assertions.
Modified:
lnt/trunk/lnt/server/db/v4db.py
Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=305723&r1=305722&r2=305723&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Mon Jun 19 12:58:16 2017
@@ -1,3 +1,4 @@
+from lnt.testing.util.commands import fatal
try:
import threading
@@ -14,6 +15,7 @@ import lnt.server.db.migrate
from lnt.server.db import testsuite
import lnt.server.db.util
+
class V4DB(object):
"""
Wrapper object for LNT v0.4+ databases.
@@ -107,26 +109,22 @@ class V4DB(object):
self.SampleField = testsuite.SampleField
# Resolve or create the known status kinds.
- self.pass_status_kind = self.query(testsuite.StatusKind)\
- .filter_by(id = lnt.testing.PASS).first()
- self.fail_status_kind = self.query(testsuite.StatusKind)\
- .filter_by(id = lnt.testing.FAIL).first()
- self.xfail_status_kind = self.query(testsuite.StatusKind)\
- .filter_by(id = lnt.testing.XFAIL).first()
- assert (self.pass_status_kind and self.fail_status_kind and
- self.xfail_status_kind), \
- "status kinds not initialized!"
+ kinds = {k.id: k for k in self.query(testsuite.StatusKind).all()}
+ try:
+ self.pass_status_kind = kinds[lnt.testing.PASS]
+ self.fail_status_kind = kinds[lnt.testing.FAIL]
+ self.xfail_status_kind = kinds[lnt.testing.XFAIL]
+ except KeyError:
+ fatal("status kinds not initialized!")
+ sample_types = {st.name: st for st in self.query(testsuite.SampleType).all()}
# Resolve or create the known sample types.
- self.real_sample_type = self.query(testsuite.SampleType)\
- .filter_by(name="Real").first()
- self.status_sample_type = self.query(testsuite.SampleType)\
- .filter_by(name="Status").first()
- self.hash_sample_type = self.query(testsuite.SampleType)\
- .filter_by(name="Hash").first()
- assert (self.real_sample_type and self.status_sample_type and
- self.hash_sample_type), \
- "sample types not initialized!"
+ try:
+ self.real_sample_type = sample_types["Real"]
+ self.status_sample_type = sample_types["Status"]
+ self.hash_sample_type = sample_types["Hash"]
+ except KeyError:
+ fatal("sample types not initialized!")
def close(self):
if self.session is not None:
More information about the llvm-commits
mailing list