@@ -988,6 +988,7 @@ IDBError SQLiteIDBBackingStore::getOrEstablishDatabaseInfo(IDBDatabaseInfo& info
988988 return IDBError { ExceptionCode::UnknownError, " Unable to open database file on disk" _s };
989989
990990 m_sqliteDB->disableThreadingChecks ();
991+ m_sqliteDB->turnOnIncrementalAutoVacuum ();
991992 m_sqliteDB->enableAutomaticWALTruncation ();
992993
993994 m_sqliteDB->setCollationFunction (" IDBKEY" _s, [](int aLength, const void * a, int bLength, const void * b) {
@@ -1036,6 +1037,10 @@ IDBError SQLiteIDBBackingStore::getOrEstablishDatabaseInfo(IDBDatabaseInfo& info
10361037
10371038 m_databaseInfo = WTFMove (databaseInfo);
10381039 info = *m_databaseInfo;
1040+
1041+ // Check if we are be able to free up some space on the file system
1042+ incrementalVacuumIfNeeded ();
1043+
10391044 return IDBError { };
10401045}
10411046
@@ -2843,6 +2848,22 @@ void SQLiteIDBBackingStore::handleLowMemoryWarning()
28432848 m_sqliteDB->releaseMemory ();
28442849}
28452850
2851+ void SQLiteIDBBackingStore::incrementalVacuumIfNeeded ()
2852+ {
2853+ ASSERT (m_sqliteDB);
2854+ ASSERT (m_sqliteDB->isOpen ());
2855+
2856+ int64_t freeSpaceSize = m_sqliteDB->freeSpaceSize ();
2857+ int64_t totalSize = m_sqliteDB->totalSize ();
2858+
2859+ if (totalSize <= 10 * freeSpaceSize) {
2860+ int result = m_sqliteDB->runIncrementalVacuumCommand ();
2861+ if (result != SQLITE_DONE)
2862+ LOG_ERROR (" Failed to perform incremental vacuum on database for path '%s'" , m_sqliteDB->utf8 ().data ());
2863+ }
2864+ }
2865+
2866+
28462867#undef TABLE_SCHEMA_PREFIX
28472868#undef V3_RECORDS_TABLE_SCHEMA_SUFFIX
28482869#undef V3_INDEX_RECORDS_TABLE_SCHEMA_SUFFIX
0 commit comments