pull/205/head
M66B 3 years ago
parent 7b9d21325d
commit b228b8313c

@ -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

@ -831,7 +831,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Log.i("Manual GC"); Log.i("Manual GC");
Runtime.getRuntime().runFinalization(); Runtime.getRuntime().runFinalization();
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
updateDebugInfo(); view.postDelayed(new Runnable() {
@Override
public void run() {
updateDebugInfo();
}
}, 1000L);
}
});
tvDebug.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
DB.shrinkMemory(view.getContext());
view.postDelayed(new Runnable() {
@Override
public void run() {
updateDebugInfo();
}
}, 1000L);
return true;
} }
}); });

@ -57,10 +57,11 @@ public class WorkerFts extends Worker {
Log.i("FTS index"); Log.i("FTS index");
Context context = getApplicationContext(); Context context = getApplicationContext();
DB.checkpoint(context);
int indexed = 0; int indexed = 0;
List<Long> ids = new ArrayList<>(INDEX_BATCH_SIZE); List<Long> ids = new ArrayList<>(INDEX_BATCH_SIZE);
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.checkpoint(context);
SQLiteDatabase sdb = FtsDbHelper.getInstance(context); SQLiteDatabase sdb = FtsDbHelper.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

Loading…
Cancel
Save