Skip to content

Commit 2e31f97

Browse files
author
Krzysztof Borowy
committed
improvements
1 parent a53961f commit 2e31f97

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncLocalStorageUtil.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,29 @@ private static void deepMergeInto(JSONObject oldJSON, JSONObject newJSON)
155155
* a "checkpoint" and is done automatically (by default) when the WAL file reaches a threshold
156156
* size of 1000 pages.
157157
* More here: https://sqlite.org/wal.html
158-
* <p>
158+
*
159159
* This helper will force checkpoint on RKStorage, if Next storage file does not exists yet.
160160
*/
161161
public static void verifyAndForceSqliteCheckpoint(Context ctx) {
162+
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
163+
Log.i("AsyncStorage_Next", "SQLite checkpoint not required on this API version.");
164+
}
165+
162166
File nextStorageFile = ctx.getDatabasePath("AsyncStorage");
163167
File currentStorageFile = ctx.getDatabasePath(ReactDatabaseSupplier.DATABASE_NAME);
164-
boolean isCheckpointRequired = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
165-
&& !nextStorageFile.exists()
166-
&& currentStorageFile.exists();
168+
boolean isCheckpointRequired = !nextStorageFile.exists() && currentStorageFile.exists();
167169
if (!isCheckpointRequired) {
168170
Log.i("AsyncStorage_Next", "SQLite checkpoint not required.");
169171
return;
170172
}
171173

172174
try {
173175
ReactDatabaseSupplier supplier = ReactDatabaseSupplier.getInstance(ctx);
174-
supplier.get().execSQL("PRAGMA wal_checkpoint");
176+
supplier.get().rawQuery("PRAGMA wal_checkpoint", null).close();
175177
supplier.closeDatabase();
176178
Log.i("AsyncStorage_Next", "Forcing SQLite checkpoint successful.");
177179
} catch (Exception e) {
178-
Log.w("AsyncStorage_Next", "Could not force checkpoint on RKStorage: " + e.getMessage());
180+
Log.w("AsyncStorage_Next", "Data migration to Next storage failed.\n" + "Could not force checkpoint on RKStorage: " + e.getMessage());
179181
}
180182
}
181183
}

android/src/main/java/com/reactnativecommunity/asyncstorage/next/StorageSupplier.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.reactnativecommunity.asyncstorage.next
22

33
import android.content.Context
4+
import android.util.Log
45
import androidx.room.ColumnInfo
56
import androidx.room.Dao
67
import androidx.room.Database
@@ -100,6 +101,7 @@ private object MIGRATION_TO_NEXT : Migration(1, 2) {
100101
FROM $oldTableName;
101102
""".trimIndent()
102103
)
104+
Log.e("AsyncStorage_Next", "Migration to Next storage completed.")
103105
}
104106
}
105107

0 commit comments

Comments
 (0)