|
|
@ -397,8 +397,9 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
for (String pragma : new String[]{
|
|
|
|
for (String pragma : new String[]{
|
|
|
|
"synchronous", "journal_mode",
|
|
|
|
"synchronous", "journal_mode",
|
|
|
|
"wal_checkpoint", "wal_autocheckpoint",
|
|
|
|
"wal_checkpoint", "wal_autocheckpoint",
|
|
|
|
"page_count", "page_size",
|
|
|
|
"page_count", "page_size", "max_page_count", "freelist_count",
|
|
|
|
"cache_size", "cache_spill"})
|
|
|
|
"cache_size", "cache_spill",
|
|
|
|
|
|
|
|
"soft_heap_limit", "hard_heap_limit", "mmap_size"})
|
|
|
|
try (Cursor cursor = db.query("PRAGMA " + pragma + ";")) {
|
|
|
|
try (Cursor cursor = db.query("PRAGMA " + pragma + ";")) {
|
|
|
|
Log.i("Get PRAGMA " + pragma + "=" + (cursor.moveToNext() ? cursor.getString(0) : "?"));
|
|
|
|
Log.i("Get PRAGMA " + pragma + "=" + (cursor.moveToNext() ? cursor.getString(0) : "?"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2153,26 +2154,53 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void checkpoint(Context context) {
|
|
|
|
public static void checkpoint(Context context) {
|
|
|
|
if (!BuildConfig.DEBUG)
|
|
|
|
if (!BuildConfig.DEBUG)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// https://www.sqlite.org/pragma.html#pragma_wal_checkpoint
|
|
|
|
// https://www.sqlite.org/pragma.html#pragma_wal_checkpoint
|
|
|
|
long start = new Date().getTime();
|
|
|
|
DB db = getInstance(context);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
db.getQueryExecutor().execute(new Runnable() {
|
|
|
|
SupportSQLiteDatabase db = getInstance(context).getOpenHelper().getWritableDatabase();
|
|
|
|
@Override
|
|
|
|
try (Cursor cursor = db.query("PRAGMA wal_checkpoint(PASSIVE);")) {
|
|
|
|
public void run() {
|
|
|
|
if (cursor.moveToNext()) {
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < cursor.getColumnCount(); i++) {
|
|
|
|
long start = new Date().getTime();
|
|
|
|
if (i > 0)
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(",");
|
|
|
|
SupportSQLiteDatabase sdb = db.getOpenHelper().getWritableDatabase();
|
|
|
|
sb.append(cursor.getInt(i));
|
|
|
|
try (Cursor cursor = sdb.query("PRAGMA wal_checkpoint(PASSIVE);")) {
|
|
|
|
|
|
|
|
if (cursor.moveToNext()) {
|
|
|
|
|
|
|
|
for (int i = 0; i < cursor.getColumnCount(); i++) {
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
|
|
|
sb.append(",");
|
|
|
|
|
|
|
|
sb.append(cursor.getInt(i));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long elapse = new Date().getTime() - start;
|
|
|
|
|
|
|
|
Log.i("PRAGMA wal_checkpoint=" + sb + " elapse=" + elapse);
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long elapse = new Date().getTime() - start;
|
|
|
|
public static void shrinkMemory(Context context) {
|
|
|
|
Log.i("PRAGMA wal_checkpoint=" + sb + " elapse=" + elapse);
|
|
|
|
DB db = getInstance(context);
|
|
|
|
|
|
|
|
db.getQueryExecutor().execute(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
SupportSQLiteDatabase sdb = db.getOpenHelper().getWritableDatabase();
|
|
|
|
|
|
|
|
try (Cursor cursor = sdb.query("PRAGMA shrink_memory;")) {
|
|
|
|
|
|
|
|
cursor.moveToNext();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|