Log statistics about the SDSKeyValueStore on internal app launch

(without blocking launch, of course)

This should help us identify which SDSKeyValueStore collections might
be better promoted to full tables.
This commit is contained in:
Jordan Rose 2022-03-04 15:30:57 -08:00
parent 6e77f78e77
commit 2f710ecc87
2 changed files with 29 additions and 1 deletions

View File

@ -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];
}
});
};

View File

@ -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