mirror of https://github.com/oxen-io/session-ios
Purge dynamic interactions from database.
parent
98137e9ddf
commit
bd40aacd53
@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SignalServiceKit
|
||||||
|
|
||||||
|
@objc
|
||||||
|
public class OWS114RemoveDynamicInteractions: OWSDatabaseMigration {
|
||||||
|
|
||||||
|
// MARK: - Dependencies
|
||||||
|
|
||||||
|
// MARK: -
|
||||||
|
|
||||||
|
// Increment a similar constant for each migration.
|
||||||
|
@objc
|
||||||
|
class func migrationId() -> String {
|
||||||
|
return "114"
|
||||||
|
}
|
||||||
|
|
||||||
|
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||||
|
Logger.debug("")
|
||||||
|
BenchAsync(title: "\(self.logTag)") { (benchCompletion) in
|
||||||
|
self.doMigrationAsync(completion: {
|
||||||
|
benchCompletion()
|
||||||
|
completion()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func doMigrationAsync(completion : @escaping OWSDatabaseMigrationCompletion) {
|
||||||
|
DispatchQueue.global().async {
|
||||||
|
self.dbReadWriteConnection().readWrite { transaction in
|
||||||
|
guard let dbView = TSDatabaseView.threadSpecialMessagesDatabaseView(transaction) as? YapDatabaseViewTransaction else {
|
||||||
|
owsFailDebug("Couldn't load db view.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var interactionsToDelete = [TSInteraction]()
|
||||||
|
let groupIds = dbView.allGroups()
|
||||||
|
for groupId in groupIds {
|
||||||
|
dbView.enumerateKeysAndObjects(inGroup: groupId) { (_: String, _: String, object: Any, _: UInt, _: UnsafeMutablePointer<ObjCBool>) in
|
||||||
|
guard let interaction = object as? TSInteraction else {
|
||||||
|
owsFailDebug("Invalid database entity: \(type(of: object)).")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard interaction.isDynamicInteraction() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
interactionsToDelete.append(interaction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for interaction in interactionsToDelete {
|
||||||
|
Logger.debug("Cleaning up interaction: \(type(of: interaction)).")
|
||||||
|
interaction.remove(with: transaction)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.save(with: transaction)
|
||||||
|
}
|
||||||
|
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue