From f1b575c3436260dadeb5cd0fe3c059a796decc41 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Tue, 10 Dec 2024 09:38:55 +0100 Subject: [PATCH] Fix excessive memory usage in the high-volume messages use case --- .../URLSessionConfiguration+PubNub.swift | 2 ++ Sources/PubNub/Models/PubNubFile.swift | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) 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/Models/PubNubFile.swift b/Sources/PubNub/Models/PubNubFile.swift index 5569f327..805eda25 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,43 @@ 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 +385,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 +395,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 +422,8 @@ public struct PubNubFileEventBase: PubNubFileEvent, Hashable { publisher: publisher, timetoken: subscription.publishTimetoken.timetoken, additionalMessage: filePayload.additionalDetails, - metadata: subscription.metadata + metadata: subscription.metadata, + customMessageType: subscription.customMessageType ) }