MCPcopy Create free account
hub / github.com/M66B/FairEmail / onOpen

Method onOpen

app/src/main/java/eu/faircode/email/DB.java:545–651  ·  view source on GitHub ↗
(@NonNull SupportSQLiteDatabase db)

Source from the content-addressed store, hash-verified

543 }
544
545 @Override
546 public void onOpen(@NonNull SupportSQLiteDatabase db) {
547 try {
548 Map<String, String> crumb = new HashMap<>();
549 crumb.put("version", Integer.toString(db.getVersion()));
550 crumb.put("WAL", Boolean.toString(db.isWriteAheadLoggingEnabled()));
551 Log.breadcrumb("Database", crumb);
552
553 // https://www.sqlite.org/pragma.html#pragma_auto_vacuum
554 // https://android.googlesource.com/platform/external/sqlite.git/+/6ab557bdc070f11db30ede0696888efd19800475%5E!/
555 boolean sqlite_auto_vacuum = prefs.getBoolean("sqlite_auto_vacuum", false);
556 String mode = (sqlite_auto_vacuum ? "FULL" : "INCREMENTAL");
557 Log.i("Set PRAGMA auto_vacuum=" + mode);
558 try (Cursor cursor = db.query("PRAGMA auto_vacuum=" + mode + ";")) {
559 cursor.moveToNext(); // required
560 }
561
562 // https://sqlite.org/pragma.html#pragma_synchronous
563 boolean sqlite_sync_extra = prefs.getBoolean("sqlite_sync_extra", true);
564 String sync = (sqlite_sync_extra ? "EXTRA" : "NORMAL");
565 Log.i("Set PRAGMA synchronous=" + sync);
566 try (Cursor cursor = db.query("PRAGMA synchronous=" + sync + ";")) {
567 cursor.moveToNext(); // required
568 }
569
570 // https://www.sqlite.org/pragma.html#pragma_journal_size_limit
571 Log.i("Set PRAGMA journal_size_limit=" + DB_JOURNAL_SIZE_LIMIT);
572 try (Cursor cursor = db.query("PRAGMA journal_size_limit=" + DB_JOURNAL_SIZE_LIMIT + ";")) {
573 cursor.moveToNext(); // required
574 }
575
576 // https://www.sqlite.org/pragma.html#pragma_cache_size
577 Integer cache_size = getCacheSizeKb(context);
578 if (cache_size != null) {
579 cache_size = -cache_size; // kibibytes
580 Log.i("Set PRAGMA cache_size=" + cache_size);
581 // TODO CASA PRAGMA does not support placeholders
582 try (Cursor cursor = db.query("PRAGMA cache_size=" + cache_size + ";")) {
583 cursor.moveToNext(); // required
584 }
585 }
586
587 // Prevent long running operations from getting an exclusive lock
588 // https://www.sqlite.org/pragma.html#pragma_cache_spill
589 Log.i("Set PRAGMA cache_spill=0");
590 try (Cursor cursor = db.query("PRAGMA cache_spill=0;")) {
591 cursor.moveToNext(); // required
592 }
593
594 Log.i("Set PRAGMA recursive_triggers=off");
595 try (Cursor cursor = db.query("PRAGMA recursive_triggers=off;")) {
596 cursor.moveToNext(); // required
597 }
598
599 // https://www.sqlite.org/pragma.html
600 for (String pragma : DB_PRAGMAS)
601 if (!"compile_options".equals(pragma) || BuildConfig.DEBUG) {
602 // TODO CASA PRAGMA does not support placeholders

Callers

nothing calls this directly

Calls 15

breadcrumbMethod · 0.95
iMethod · 0.95
getCacheSizeKbMethod · 0.95
eMethod · 0.95
dropTriggersMethod · 0.95
createTriggersMethod · 0.95
dataUpdatesMethod · 0.95
logMethod · 0.95
forceCrashReportMethod · 0.95
getBooleanMethod · 0.80
moveToNextMethod · 0.80
isNullMethod · 0.80

Tested by

no test coverage detected