diff --git a/SignalMessaging/environment/AppSetup.m b/SignalMessaging/environment/AppSetup.m index 0abb6ad75b..e23f3fcc75 100644 --- a/SignalMessaging/environment/AppSetup.m +++ b/SignalMessaging/environment/AppSetup.m @@ -235,6 +235,11 @@ NS_ASSUME_NONNULL_BEGIN backgroundTask = nil; }]; }); + + // Do this after we've let the main thread know that storage setup is complete. + if (SSKDebugFlags.internalLogging) { + [SDSKeyValueStore logCollectionStatistics]; + } }); }; diff --git a/SignalServiceKit/src/Storage/Database/SDSKeyValueStore.swift b/SignalServiceKit/src/Storage/Database/SDSKeyValueStore.swift index ef011f7f7b..14143157be 100644 --- a/SignalServiceKit/src/Storage/Database/SDSKeyValueStore.swift +++ b/SignalServiceKit/src/Storage/Database/SDSKeyValueStore.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2021 Open Whisper Systems. All rights reserved. +// Copyright (c) 2022 Open Whisper Systems. All rights reserved. // import Foundation @@ -63,6 +63,29 @@ public class SDSKeyValueStore: NSObject { try statement.execute() } + @objc + public class func logCollectionStatistics() { + Logger.info("SDSKeyValueStore statistics:") + databaseStorage.read { transaction in + do { + let sql = """ + SELECT \(collectionColumn.columnName), COUNT(*) + FROM \(table.tableName) + GROUP BY \(collectionColumn.columnName) + ORDER BY COUNT(*) DESC + """ + let cursor = try Row.fetchCursor(transaction.unwrapGrdbRead.database, sql: sql) + while let row = try cursor.next() { + let collection: String = row[0] + let count: UInt = row[1] + Logger.info("- \(collection): \(count) items") + } + } catch { + Logger.error("\(error)") + } + } + } + // MARK: Class Helpers @objc