From 3518d37c3e32ae34e6b54d5f714225ea1abc777a Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 27 Sep 2018 07:44:37 -0600 Subject: [PATCH] use autorelease pool in migration to avoid accumulating memory --- .../migrations/OWS110SortIdMigration.swift | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/SignalMessaging/environment/migrations/OWS110SortIdMigration.swift b/SignalMessaging/environment/migrations/OWS110SortIdMigration.swift index 3fc22671d..ef35b5665 100644 --- a/SignalMessaging/environment/migrations/OWS110SortIdMigration.swift +++ b/SignalMessaging/environment/migrations/OWS110SortIdMigration.swift @@ -44,16 +44,27 @@ class OWS110SortIdMigration: OWSDatabaseMigration { return } + let totalCount: UInt = legacySorting.numberOfItemsInAllGroups() + var completedCount: UInt = 0 legacySorting.enumerateGroups { group, _ in - legacySorting.enumerateKeysAndObjects(inGroup: group) { (_, _, object, _, _) in - guard let interaction = object as? TSInteraction else { - owsFailDebug("unexpected object: \(type(of: object))") - return - } + autoreleasepool { + legacySorting.enumerateKeysAndObjects(inGroup: group) { (_, _, object, _, _) in + autoreleasepool { + guard let interaction = object as? TSInteraction else { + owsFailDebug("unexpected object: \(type(of: object))") + return + } + + interaction.saveNextSortId(transaction: transaction) - interaction.saveNextSortId(transaction: transaction) - // Legit usage of legacy sorting for migration to new sorting - Logger.debug("thread: \(interaction.uniqueThreadId), timestampForLegacySorting:\(interaction.timestampForLegacySorting()), sortId: \(interaction.sortId)") + completedCount += 1 + + if completedCount % 100 == 0 { + // Legit usage of legacy sorting for migration to new sorting + Logger.info("thread: \(interaction.uniqueThreadId), timestampForLegacySorting:\(interaction.timestampForLegacySorting()), sortId: \(interaction.sortId) totalCount: \(totalCount), completedcount: \(completedCount)") + } + } + } } }