Skip to content

Commit c55790e

Browse files
Optimized sending of http requests
1 parent 8bbd494 commit c55790e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
222222
// MARK: - private
223223

224224
private func checkForNewMessages(index: Int) {
225-
if index < channelDataSource.messages.count - 25 {
225+
if index < channelDataSource.messages.count - 20 {
226226
return
227227
}
228228

Sources/StreamChatSwiftUI/ChatChannelList/ChannelHeaderLoader.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ open class ChannelHeaderLoader: ObservableObject {
1414
/// The maximum number of images that combine to form a single avatar
1515
private let maxNumberOfImagesInCombinedAvatar = 4
1616

17+
/// Prevents image requests to be executed if they failed previously.
18+
private var failedImageLoads = Set<String>()
19+
1720
/// Context provided utils.
1821
internal lazy var imageLoader = utils.imageLoader
1922
internal lazy var imageCDN = utils.imageCDN
@@ -96,6 +99,10 @@ open class ChannelHeaderLoader: ObservableObject {
9699
for channel: ChatChannel,
97100
from url: URL
98101
) {
102+
if failedImageLoads.contains(channel.cid.id) {
103+
return
104+
}
105+
99106
imageLoader.loadImage(
100107
url: url,
101108
imageCDN: imageCDN,
@@ -109,6 +116,7 @@ open class ChannelHeaderLoader: ObservableObject {
109116
self.loadedImages[channel.cid.id] = image
110117
}
111118
case let .failure(error):
119+
self.failedImageLoads.insert(channel.cid.id)
112120
log.error("error loading image: \(error.localizedDescription)")
113121
}
114122
}

0 commit comments

Comments
 (0)