Skip to content

Commit

Permalink
Adds places db cleanup in a background queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarik Eshaq committed Jan 4, 2023
1 parent c725f53 commit 95fbc31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Client/Application/UITestAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class UITestAppDelegate: AppDelegate, FeatureFlaggable {
try! FileManager.default.copyItem(at: input, to: output)

// Tests currently load a browserdb history, we make sure we migrate it everytime
UserDefaults.standard.setValue(false, forKey: PrefsKeys.HistoryMigratedToPlacesKey)
UserDefaults.standard.setValue(false, forKey: PrefsKeys.PlacesHistoryMigrationSucceeded)
}

if arg.starts(with: LaunchArguments.LoadTabsStateArchive) {
Expand Down
10 changes: 5 additions & 5 deletions Providers/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ open class BrowserProfile: Profile {
}

public func cleanupHistoryIfNeeded() {
// currently a no-op, but we should call
// places.runMaintenace here. At the time of writing this comment,
// it was run in Android once a day when the device is idle
// we should do something similar in iOS
// https://github.com/mozilla-mobile/firefox-ios/issues/12680
// We run the cleanup in the background, this is a low priority task
// that compacts the places db and reduces it's size to be under the limit.
DispatchQueue.global(qos: .background).async {
self.places.runMaintenance(dbSizeLimit: AppConstants.DB_SIZE_LIMIT_IN_BYTES)
}
}

public func sendQueuedSyncEvents() {
Expand Down
3 changes: 3 additions & 0 deletions Shared/AppConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ public struct AppConstants {

/// The maximum number of times we should attempt to migrated the History to Application Services Places DB
public static let MAX_HISTORY_MIGRATION_ATTEMPT = 5

/// The maximum size of the places DB in bytes
public static let DB_SIZE_LIMIT_IN_BYTES: UInt32 = 75 * 1024 * 1024 // corresponds to 75MiB (in bytes)
}

0 comments on commit 95fbc31

Please sign in to comment.