From 670dc920deaf64a99f6ca3ad10ba19029493f3ff Mon Sep 17 00:00:00 2001 From: David Goetz Date: Fri, 25 Jul 2014 12:16:54 -0700 Subject: [PATCH] Reuse a cursor instead of a conn.execute for better performance In some limited testing it was ~10% faster. Every little bit helps right? Change-Id: Ide55b7600d625ad151daca73fbdd8684f0f9e7f8 --- swift/container/backend.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/swift/container/backend.py b/swift/container/backend.py index ff5129f142..37319ed85d 100644 --- a/swift/container/backend.py +++ b/swift/container/backend.py @@ -701,6 +701,7 @@ class ContainerBroker(DatabaseBroker): """ def _really_merge_items(conn): max_rowid = -1 + curs = conn.cursor() for rec in item_list: rec.setdefault('storage_policy_index', 0) # legacy query = ''' @@ -710,7 +711,7 @@ class ContainerBroker(DatabaseBroker): ''' if self.get_db_version(conn) >= 1: query += ' AND deleted IN (0, 1)' - conn.execute(query, (rec['name'], rec['created_at'], + curs.execute(query, (rec['name'], rec['created_at'], rec['storage_policy_index'])) query = ''' SELECT 1 FROM object WHERE name = ? @@ -718,9 +719,9 @@ class ContainerBroker(DatabaseBroker): ''' if self.get_db_version(conn) >= 1: query += ' AND deleted IN (0, 1)' - if not conn.execute(query, ( + if not curs.execute(query, ( rec['name'], rec['storage_policy_index'])).fetchall(): - conn.execute(''' + curs.execute(''' INSERT INTO object (name, created_at, size, content_type, etag, deleted, storage_policy_index) VALUES (?, ?, ?, ?, ?, ?, ?)