From b72ec5f7229a6371894666bb242799d89a72f36c Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Sun, 26 Jan 2014 18:54:22 -0400 Subject: add pragmas for temp_store=mem and synchronous=off controlled by environmental variables --- client/changes/feature_sqlite-optimization-pragmas | 1 + client/src/leap/soledad/client/sqlcipher.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 client/changes/feature_sqlite-optimization-pragmas diff --git a/client/changes/feature_sqlite-optimization-pragmas b/client/changes/feature_sqlite-optimization-pragmas new file mode 100644 index 00000000..7a35f005 --- /dev/null +++ b/client/changes/feature_sqlite-optimization-pragmas @@ -0,0 +1 @@ + o Add sync=off and tem_store=mem to soledad client, for optimization. diff --git a/client/src/leap/soledad/client/sqlcipher.py b/client/src/leap/soledad/client/sqlcipher.py index 43c871c3..ef059e9b 100644 --- a/client/src/leap/soledad/client/sqlcipher.py +++ b/client/src/leap/soledad/client/sqlcipher.py @@ -190,6 +190,10 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase): self._set_crypto_pragmas( self._db_handle, password, raw_key, cipher, kdf_iter, cipher_page_size) + if os.environ.get('LEAP_SQLITE_NOSYNC'): + self._pragma_synchronous_off(self._db_handle) + if os.environ.get('LEAP_SQLITE_MEMSTORE'): + self._pragma_mem_temp_store(self._db_handle) self._real_replica_uid = None self._ensure_schema() self._crypto = crypto @@ -734,6 +738,22 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase): # XXX change passphrase param! db_handle.cursor().execute('PRAGMA rekey = "x\'%s"' % passphrase) + @classmethod + def _pragma_synchronous_off(cls, db_handle): + """ + Change the setting of the "synchronous" flag to OFF. + """ + logger.debug("SQLCIPHER: SETTING SYNCHRONOUS OFF") + db_handle.cursor().execute('PRAGMA synchronous=OFF') + + @classmethod + def _pragma_mem_temp_store(cls, db_handle): + """ + Use a in-memory store for temporary tables. + """ + logger.debug("SQLCIPHER: SETTING TEMP_STORE MEMORY") + db_handle.cursor().execute('PRAGMA temp_store=MEMORY') + # Extra query methods: extensions to the base sqlite implmentation. def get_count_from_index(self, index_name, *key_values): -- cgit v1.2.3