@@ -56,30 +56,24 @@ class OTRStorageUsageViewController : XLFormViewController {
5656 private func processAllMedia( ) {
5757 var empty = true
5858 connections? . read. read { ( transaction: YapDatabaseReadTransaction ) in
59- transaction. enumerateKeysAndObjects ( inCollection: OTRMediaItem . collection, using: { ( key, object, stop) in
60- if let mediaItem = object as? OTRMediaItem {
61- let parentMessage = mediaItem. parentMessage ( with: transaction) as? OTRBaseMessage
62-
63- if let threadOwner = parentMessage? . threadOwner ( with: transaction) ,
64- let account = threadOwner. account ( with: transaction) {
65- do {
66- let length = try OTRMediaFileManager . shared. dataLength ( for: mediaItem, buddyUniqueId: threadOwner. threadIdentifier)
67- empty = false
68-
69- let section = sectionForAccount ( account)
70- let row = rowForThreadOwner ( threadOwner, section)
71- let value = row. value as? Int ?? 0
72- row. value = value + length. intValue
73-
74- DispatchQueue . main. async {
75- self . updateFormRow ( row)
76- }
77- } catch {
78- return
79- }
80- }
59+ transaction. iterateKeysAndObjects ( inCollection: OTRMediaItem . collection) { ( key, mediaItem: OTRMediaItem , stop) in
60+ let parentMessage = mediaItem. parentMessage ( with: transaction) as? OTRBaseMessage
61+ guard let threadOwner = parentMessage? . threadOwner ( with: transaction) ,
62+ let account = threadOwner. account ( with: transaction) ,
63+ let length = try ? OTRMediaFileManager . shared. dataLength ( for: mediaItem, buddyUniqueId: threadOwner. threadIdentifier) else {
64+ return
65+ }
66+ empty = false
67+
68+ let section = sectionForAccount ( account)
69+ let row = rowForThreadOwner ( threadOwner, section)
70+ let value = row. value as? Int ?? 0
71+ row. value = value + length. intValue
72+
73+ DispatchQueue . main. async {
74+ self . updateFormRow ( row)
8175 }
82- } )
76+ }
8377 }
8478 if let deleteAll = self . form. formRow ( withTag: DELETE_ALL_TAG) ,
8579 let noMediaFound = self . form. formRow ( withTag: NO_MEDIA_FOUND_TAG) {
@@ -135,19 +129,17 @@ class OTRStorageUsageViewController : XLFormViewController {
135129
136130 private func findItemsToDelete( _ transaction: YapDatabaseReadWriteTransaction , _ threadIdentifier: String ? ) -> [ OTRMediaItem ] {
137131 var mediaItemsToDelete : [ OTRMediaItem ] = [ ]
138- transaction. enumerateKeysAndObjects ( inCollection: OTRMediaItem . collection, using: { ( key, object, stop) in
139- if let mediaItem = object as? OTRMediaItem {
140- let parentMessage = mediaItem. parentMessage ( with: transaction) as? OTRBaseMessage
141- if threadIdentifier != nil ,
142- let threadOwner = parentMessage? . threadOwner ( with: transaction) ,
143- threadOwner. threadIdentifier != threadIdentifier {
144- return
145- }
146- if ( parentMessage? . mediaItemUniqueId != nil ) {
147- mediaItemsToDelete. append ( mediaItem)
148- }
132+ transaction. iterateKeysAndObjects ( inCollection: OTRMediaItem . collection) { ( key, mediaItem: OTRMediaItem , stop) in
133+ let parentMessage = mediaItem. parentMessage ( with: transaction) as? OTRBaseMessage
134+ if threadIdentifier != nil ,
135+ let threadOwner = parentMessage? . threadOwner ( with: transaction) ,
136+ threadOwner. threadIdentifier != threadIdentifier {
137+ return
149138 }
150- } )
139+ if ( parentMessage? . mediaItemUniqueId != nil ) {
140+ mediaItemsToDelete. append ( mediaItem)
141+ }
142+ }
151143 return mediaItemsToDelete
152144 }
153145
0 commit comments