From 299aa62f5d22a5942e0b3a61eaa6cc0353770b0e Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Mon, 3 May 2021 21:48:58 +0200 Subject: 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. --- quarg/main.py | 15 ++++++++------- 1 file 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)) -- cgit v1.2.3-2-gb3c3