Compact the DB at shutdown, and at startup if not closed cleanly.

This commit is contained in:
akwizgran
2022-03-01 12:28:09 +00:00
parent 101ffa2f08
commit e66152e812
4 changed files with 13 additions and 6 deletions

View File

@@ -85,12 +85,17 @@ class H2Database extends JdbcDatabase {
public void close() throws DbException {
// H2 will close the database when the last connection closes
Connection c = null;
Statement s = null;
try {
c = createConnection();
super.closeAllConnections();
closeAllConnections();
setDirty(c, false);
s = c.createStatement();
s.execute("SHUTDOWN COMPACT");
s.close();
c.close();
} catch (SQLException e) {
tryToClose(s, LOG, WARNING);
tryToClose(c, LOG, WARNING);
throw new DbException(e);
}

View File

@@ -79,11 +79,11 @@ class HyperSqlDatabase extends JdbcDatabase {
Connection c = null;
Statement s = null;
try {
super.closeAllConnections();
closeAllConnections();
c = createConnection();
setDirty(c, false);
s = c.createStatement();
s.executeQuery("SHUTDOWN");
s.executeQuery("SHUTDOWN COMPACT");
s.close();
c.close();
} catch (SQLException e) {
@@ -106,7 +106,7 @@ class HyperSqlDatabase extends JdbcDatabase {
Connection c = null;
Statement s = null;
try {
super.closeAllConnections();
closeAllConnections();
c = createConnection();
s = c.createStatement();
s.executeQuery("SHUTDOWN COMPACT");

View File

@@ -405,7 +405,9 @@ abstract class JdbcDatabase implements Database<Connection> {
if (reopen) {
Settings s = getSettings(txn, DB_SETTINGS_NAMESPACE);
wasDirtyOnInitialisation = isDirty(s);
compact = migrateSchema(txn, s, listener) || isCompactionDue(s);
boolean migrated = migrateSchema(txn, s, listener);
compact = wasDirtyOnInitialisation || migrated
|| isCompactionDue(s);
} else {
wasDirtyOnInitialisation = false;
createTables(txn);

View File

@@ -17,7 +17,7 @@
app:layout_constraintVertical_bias="0.5"
app:layout_constraintVertical_chainStyle="packed"
app:srcCompat="@drawable/startup_lock"
app:tint="@color/briar_primary"
app:tint="@color/briar_accent"
tools:ignore="ContentDescription" />
<ProgressBar