From 771973e7a6440581d8ca2b7e0cb85f670c1a5c04 Mon Sep 17 00:00:00 2001 From: jguz-pubnub <102806147+jguz-pubnub@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:21:42 +0100 Subject: [PATCH] Fix excessive memory usage in the high-volume messages use case (#196) fix(subscribe): fix excessive memory usage in the high-volume messages use case fix(custom-message-type): add missing `customMessageType` in `PubNubFileEvent` --- .pubnub.yml | 11 ++++++-- PubNub.xcodeproj/project.pbxproj | 16 ++++++------ PubNubSwift.podspec | 2 +- .../URLSessionConfiguration+PubNub.swift | 2 ++ Sources/PubNub/Helpers/Constants.swift | 2 +- .../KMP/Wrappers/KMPFileChangeEvent.swift | 4 +++ Sources/PubNub/Models/PubNubFile.swift | 26 ++++++++++++------- 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 751d1ceb..2f9dc9e0 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,9 +1,16 @@ --- name: swift scm: github.com/pubnub/swift -version: "8.2.1" +version: "8.2.2" schema: 1 changelog: + - date: 2024-12-11 + version: 8.2.2 + changes: + - type: bug + text: "Fix excessive memory usage in the high-volume messages use case." + - type: bug + text: "Add missing `customMessageType` in `PubNubFileEvent`." - date: 2024-12-09 version: 8.2.1 changes: @@ -624,7 +631,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: PubNub - location: https://github.com/pubnub/swift/archive/refs/tags/8.2.1.zip + location: https://github.com/pubnub/swift/archive/refs/tags/8.2.2.zip supported-platforms: supported-operating-systems: macOS: diff --git a/PubNub.xcodeproj/project.pbxproj b/PubNub.xcodeproj/project.pbxproj index a4f0d0cb..0deb79bf 100644 --- a/PubNub.xcodeproj/project.pbxproj +++ b/PubNub.xcodeproj/project.pbxproj @@ -3995,7 +3995,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17"; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -4046,7 +4046,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; @@ -4154,7 +4154,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17"; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -4207,7 +4207,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; @@ -4328,7 +4328,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17"; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -4380,7 +4380,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; @@ -4860,7 +4860,7 @@ "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14"; OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; @@ -4903,7 +4903,7 @@ "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 8.2.1; + MARKETING_VERSION = 8.2.2; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14"; OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; diff --git a/PubNubSwift.podspec b/PubNubSwift.podspec index 23308a05..8c70511c 100644 --- a/PubNubSwift.podspec +++ b/PubNubSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'PubNubSwift' - s.version = '8.2.1' + s.version = '8.2.2' s.homepage = 'https://github.com/pubnub/swift' s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk' s.authors = { 'PubNub, Inc.' => 'support@pubnub.com' } diff --git a/Sources/PubNub/Extensions/URLSessionConfiguration+PubNub.swift b/Sources/PubNub/Extensions/URLSessionConfiguration+PubNub.swift index 69361dd7..0293e43a 100644 --- a/Sources/PubNub/Extensions/URLSessionConfiguration+PubNub.swift +++ b/Sources/PubNub/Extensions/URLSessionConfiguration+PubNub.swift @@ -50,6 +50,8 @@ public extension URLSessionConfiguration { let configuration = URLSessionConfiguration.pubnub configuration.timeoutIntervalForRequest += Constant.minimumSubscribeRequestTimeout configuration.httpMaximumConnectionsPerHost = 1 + configuration.requestCachePolicy = .reloadIgnoringLocalCacheData + configuration.urlCache = nil return configuration } diff --git a/Sources/PubNub/Helpers/Constants.swift b/Sources/PubNub/Helpers/Constants.swift index 42dc2182..1ef03510 100644 --- a/Sources/PubNub/Helpers/Constants.swift +++ b/Sources/PubNub/Helpers/Constants.swift @@ -57,7 +57,7 @@ public enum Constant { static let pubnubSwiftSDKName: String = "PubNubSwift" - static let pubnubSwiftSDKVersion: String = "8.2.1" + static let pubnubSwiftSDKVersion: String = "8.2.2" static let appBundleId: String = { if let info = Bundle.main.infoDictionary, diff --git a/Sources/PubNub/KMP/Wrappers/KMPFileChangeEvent.swift b/Sources/PubNub/KMP/Wrappers/KMPFileChangeEvent.swift index 123687d9..d5dd8032 100644 --- a/Sources/PubNub/KMP/Wrappers/KMPFileChangeEvent.swift +++ b/Sources/PubNub/KMP/Wrappers/KMPFileChangeEvent.swift @@ -24,6 +24,7 @@ public class KMPFileChangeEvent: NSObject { @objc public let publisher: String? @objc public let message: KMPAnyJSON? @objc public let metadata: KMPAnyJSON? + @objc public let customMessageType: String? @objc public let subscription: String? @objc public let file: KMPFile @@ -36,6 +37,7 @@ public class KMPFileChangeEvent: NSObject { publisher: fileEvent.publisher, message: fileEvent.additionalMessage?.codableValue, metadata: fileEvent.metadata?.codableValue, + customMessageType: fileEvent.customMessageType, subscription: fileEvent.channelGroup, file: KMPFile( from: fileEvent.file, @@ -51,6 +53,7 @@ public class KMPFileChangeEvent: NSObject { publisher: String?, message: AnyJSON?, metadata: AnyJSON?, + customMessageType: String?, subscription: String?, file: KMPFile ) { @@ -59,6 +62,7 @@ public class KMPFileChangeEvent: NSObject { self.publisher = publisher self.message = if let message = message { KMPAnyJSON(message) } else { nil } self.metadata = if let metadata = metadata { KMPAnyJSON(metadata) } else { nil } + self.customMessageType = customMessageType self.subscription = subscription self.file = file } diff --git a/Sources/PubNub/Models/PubNubFile.swift b/Sources/PubNub/Models/PubNubFile.swift index 5569f327..653f7804 100644 --- a/Sources/PubNub/Models/PubNubFile.swift +++ b/Sources/PubNub/Models/PubNubFile.swift @@ -305,6 +305,8 @@ public protocol PubNubFileEvent { var additionalMessage: JSONCodable? { get } /// Meta information for the event var metadata: JSONCodable? { get } + /// A user-provided custom message type + var customMessageType: String? { get set } /// Allows for converting between different `PubNubFileEvent` types init(from other: PubNubFileEvent) throws @@ -339,39 +341,42 @@ public struct PubNubFileEventBase: PubNubFileEvent, Hashable { public var channelGroup: String? public var publisher: String public var timetoken: Timetoken + public var customMessageType: String? - var concreteFile: PubNubFileBase public var file: PubNubFile { - return concreteFile + concreteFile } - var concreteAdditionalMessage: AnyJSON? public var additionalMessage: JSONCodable? { get { - return concreteAdditionalMessage + concreteAdditionalMessage } set { concreteAdditionalMessage = newValue?.codableValue } } - var concreteMeta: AnyJSON? public var metadata: JSONCodable? { get { - return concreteMeta + concreteMeta } set { concreteMeta = newValue?.codableValue } } + var concreteFile: PubNubFileBase + var concreteAdditionalMessage: AnyJSON? + var concreteMeta: AnyJSON? + public init( file: PubNubFile, channelGroup: String?, publisher: String, timetoken: Timetoken, additionalMessage: JSONCodable?, - metadata: JSONCodable? + metadata: JSONCodable?, + customMessageType: String? = nil ) { concreteFile = PubNubFileBase(from: file) self.channelGroup = channelGroup @@ -379,6 +384,7 @@ public struct PubNubFileEventBase: PubNubFileEvent, Hashable { self.timetoken = timetoken self.additionalMessage = additionalMessage self.metadata = metadata + self.customMessageType = customMessageType } public init(from other: PubNubFileEvent) throws { @@ -388,7 +394,8 @@ public struct PubNubFileEventBase: PubNubFileEvent, Hashable { publisher: other.publisher, timetoken: other.timetoken, additionalMessage: other.additionalMessage, - metadata: other.metadata + metadata: other.metadata, + customMessageType: other.customMessageType ) } @@ -414,7 +421,8 @@ public struct PubNubFileEventBase: PubNubFileEvent, Hashable { publisher: publisher, timetoken: subscription.publishTimetoken.timetoken, additionalMessage: filePayload.additionalDetails, - metadata: subscription.metadata + metadata: subscription.metadata, + customMessageType: subscription.customMessageType ) }