From 6f6912aadfd00d61dc473cf9ce551a31a92811d8 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 6 Jan 2020 21:22:50 +0100 Subject: [PATCH] Fix store --- lib/utils/sqflite_store.dart | 18 ++++++++---------- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/utils/sqflite_store.dart b/lib/utils/sqflite_store.dart index c3da0aa1..a385a3d5 100644 --- a/lib/utils/sqflite_store.dart +++ b/lib/utils/sqflite_store.dart @@ -53,10 +53,7 @@ class Store extends StoreAPI { onCreate: (Database db, int version) async { await createTables(db); }, onUpgrade: (Database db, int oldVersion, int newVersion) async { - if (client.debug) { - print( - "[Store] Migrate databse from version $oldVersion to $newVersion"); - } + print("[Store] Migrate databse from version $oldVersion to $newVersion"); if (oldVersion != newVersion) { schemes.forEach((String name, String scheme) async { if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name"); @@ -73,6 +70,7 @@ class Store extends StoreAPI { .rawQuery("SELECT * FROM Clients WHERE client=?", [client.clientName]); if (list.length == 1) { var clientList = list[0]; + print("[Store] Previous batch: '${clientList["prev_batch"].toString()}'"); client.connect( newToken: clientList["token"], newHomeserver: clientList["homeserver"], @@ -132,19 +130,19 @@ class Store extends StoreAPI { return; } - Future transaction(Future queries()) async { + Future transaction(Function queries) async { return _db.transaction((txnObj) async { - txn = txnObj; - await queries(); + txn = txnObj.batch(); + queries(); + await txn.commit(noResult: true); }); } /// Will be automatically called on every synchronisation. Must be called inside of // /// [transaction]. - Future storePrevBatch(dynamic sync) { + void storePrevBatch(String prevBatch) { txn.rawUpdate("UPDATE Clients SET prev_batch=? WHERE client=?", - [client.prevBatch, client.clientName]); - return null; + [prevBatch, client.clientName]); } Future storeRoomPrevBatch(Room room) async { diff --git a/pubspec.lock b/pubspec.lock index 586a6980..b398bf01 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -82,8 +82,8 @@ packages: dependency: "direct main" description: path: "." - ref: "3fbb837f85dc40e741677823f323ad8c3eac6014" - resolved-ref: "3fbb837f85dc40e741677823f323ad8c3eac6014" + ref: "45744331ead079443e0dcb280a86867af2e21ccf" + resolved-ref: "45744331ead079443e0dcb280a86867af2e21ccf" url: "https://gitlab.com/famedly/famedlysdk.git" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 85f6b4cf..b98bba7d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: famedlysdk: git: url: https://gitlab.com/famedly/famedlysdk.git - ref: 3fbb837f85dc40e741677823f323ad8c3eac6014 + ref: 45744331ead079443e0dcb280a86867af2e21ccf localstorage: ^3.0.1+4 bubble: ^1.1.9+1