From fc448a6ba12b15a30afa177cd1e02534d421f18c Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Sat, 26 Oct 2019 02:51:38 +0100 Subject: [PATCH] Fix sync token behaviour --- storage.py | 4 ++-- sync_token.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/storage.py b/storage.py index c5676a9..65473df 100644 --- a/storage.py +++ b/storage.py @@ -44,5 +44,5 @@ class Storage(object): def _run_migrations(self): """Execute database migrations""" # Initialize a connection to the database - conn = sqlite3.connect(self.db_path) - self.cursor = conn.cursor() + self.conn = sqlite3.connect(self.db_path) + self.cursor = self.conn.cursor() diff --git a/sync_token.py b/sync_token.py index 7d87a43..f805793 100644 --- a/sync_token.py +++ b/sync_token.py @@ -1,3 +1,7 @@ +import logging + +logger = logging.getLogger(__name__) + class SyncToken(object): """A SyncToken is an instance of a sync token, which is a token retrieved from a matrix homeserver. It is given to the /sync endpoint in order to specify at which point in the @@ -24,10 +28,12 @@ class SyncToken(object): self.token = rows[0] def update(self, token): - """Update the sync token in the database + """Update the sync token in the database and the object Args: token (str): A sync token from a sync response sent by a matrix homeserver """ + self.token = token self.store.cursor.execute("INSERT OR REPLACE INTO sync_token " - "(token) VALUES (?)", (token,)) + "(dedupe_id, token) VALUES (1, ?)", (token,)) + self.store.conn.commit()