Skip to content

Commit

Permalink
Fix excessive memory usage in the high-volume messages use case
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Dec 10, 2024
1 parent 4ff9421 commit f1b575c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
29 changes: 19 additions & 10 deletions Sources/PubNub/Models/PubNubFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -339,46 +341,51 @@ 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
self.publisher = publisher
self.timetoken = timetoken
self.additionalMessage = additionalMessage
self.metadata = metadata
self.customMessageType = customMessageType
}

public init(from other: PubNubFileEvent) throws {
Expand All @@ -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
)
}

Expand All @@ -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
)
}

Expand Down

0 comments on commit f1b575c

Please sign in to comment.