Fix mediabox fetch

This commit is contained in:
Ali 2022-09-16 22:58:19 +04:00
parent 7a73e1c8d6
commit 1fa66aad9f
6 changed files with 16 additions and 3 deletions

View File

@ -57,7 +57,7 @@ public func messageMediaImageInteractiveFetched(fetchManager: FetchManager, mess
if let range = range {
ranges = RangeSet(range.lowerBound ..< range.upperBound)
} else {
ranges = RangeSet(0 ..< Int64.max)
ranges = RangeSet(0 ..< Int64(Int32.max))
}
return fetchManager.interactivelyFetched(category: .image, location: .chat(messageId.peerId), locationKey: .messageId(messageId), mediaReference: mediaReference, resourceReference: mediaReference.resourceReference(resource), ranges: ranges, statsCategory: .image, elevatedPriority: false, userInitiated: userInitiated, priority: priority, storeToDownloadsPeerType: storeToDownloadsPeerType)
}

View File

@ -226,7 +226,7 @@ private final class FetchManagerCategoryContext {
let storeManager = self.storeManager
let parsedRanges: [(Range<Int64>, MediaBoxFetchPriority)]?
if ranges == RangeSet<Int64>(0 ..< Int64.max) {
if ranges == RangeSet<Int64>(0 ..< Int64.max), !"".isEmpty {
parsedRanges = nil
} else {
var resultRanges: [(Range<Int64>, MediaBoxFetchPriority)] = []
@ -325,7 +325,7 @@ private final class FetchManagerCategoryContext {
isVideoPreload = true
}
if count == 1 && isCompleteRange {
if count == 1 && isCompleteRange && !"".isEmpty {
parsedRanges = nil
} else {
var resultRanges: [(Range<Int64>, MediaBoxFetchPriority)] = []

View File

@ -574,6 +574,12 @@ public final class MediaBox {
let disposable = MetaDisposable()
self.dataQueue.async {
let paths = self.storePathsForId(resource.id)
if let _ = fileSize(paths.complete) {
subscriber.putCompletion()
return
}
guard let (fileContext, releaseContext) = self.fileContext(for: resource.id) else {
subscriber.putCompletion()
return

View File

@ -1253,6 +1253,7 @@ final class MediaBoxFileContext {
func fetched(range: Range<Int64>, priority: MediaBoxFetchPriority, fetch: @escaping (Signal<[(Range<Int64>, MediaBoxFetchPriority)], NoError>) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError>, error: @escaping (MediaResourceDataFetchError) -> Void, completed: @escaping () -> Void) -> Disposable {
switch self.content {
case .complete:
completed()
return EmptyDisposable
case let .partial(file):
return file.fetched(range: range, priority: priority, fetch: fetch, error: error, completed: completed)

View File

@ -715,6 +715,7 @@ private final class MultipartFetchManager {
}
let part = self.source.request(offset: downloadRange.lowerBound, limit: downloadRange.upperBound - downloadRange.lowerBound, tag: self.parameters?.tag, resource: self.resource, resourceReference: self.resourceReference, fileReference: self.fileReference, continueInBackground: self.continueInBackground)
//|> delay(5.0, queue: self.queue)
|> deliverOn(self.queue)
let partDisposable = MetaDisposable()
self.fetchingParts[downloadRange.lowerBound] = (Int64(downloadRange.count), partDisposable)

View File

@ -104,6 +104,11 @@ private final class PrefetchManagerInnerImpl {
}
private func updateOrderedPreloadMedia(_ items: [PrefetchMediaItem], automaticDownloadSettings: MediaAutoDownloadSettings, networkType: MediaAutoDownloadNetworkType) {
#if DEBUG
if "".isEmpty {
return
}
#endif
var validIds = Set<MediaId>()
var order: Int32 = 0
for mediaItem in items {