aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-05-03 21:48:58 +0200
committerWolfgang Müller2021-05-03 22:03:02 +0200
commit299aa62f5d22a5942e0b3a61eaa6cc0353770b0e (patch)
tree02457a2098f7a76d5911486a3f5bdbb64e71746e
parent735b60f32b1e3371d147f3f4df77a2a5b54256ad (diff)
downloadquarg-299aa62f5d22a5942e0b3a61eaa6cc0353770b0e.tar.gz
main: Split run_query into prepare_query and time_query
This commit cleanly separates the preparation, execution, and timing of a query. When preparing this commit, we realized that the preparation of the query was included in the timer calculation. This should not have been the case and has been fixed.
Diffstat (limited to '')
-rw-r--r--quarg/main.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/quarg/main.py b/quarg/main.py
index 69c99de..ce72310 100644
--- a/quarg/main.py
+++ b/quarg/main.py
@@ -96,9 +96,7 @@ def collect_predicates(args):
else:
yield fun(value)
-def run_query(session, predicates, args):
- start = timer()
-
+def prepare_query(session, predicates, args):
query = session.query(Backlog).join(Sender).join(Buffer).join(Network).join(QuasselUser)
for predicate in predicates:
@@ -113,11 +111,13 @@ def run_query(session, predicates, args):
if args.limit:
query = query.limit(args.limit)
- rows = query.all()
+ return query
+def time_query(query):
+ start = timer()
+ rows = query.all()
end = timer()
-
- return (rows, end - start)
+ return rows, end - start
def main():
config = get_config()
@@ -136,7 +136,8 @@ def main():
if not predicates:
errx('Nothing to match.')
- rows, time = run_query(session, predicates, args)
+ query = prepare_query(session, predicates, args)
+ rows, time = time_query(query)
for row in rows:
print(format_from(row))