pinterest / PINRemoteImage

A thread safe, performant, feature rich image fetcher
Apache License 2.0
4.01k stars 510 forks source link

How to change image download priority for a non-progressive image? #472

Open kgaidis opened 6 years ago

kgaidis commented 6 years ago

PINRemoteImageManager seems to expose only one way to set priority: - (void)setPriority:(PINRemoteImageManagerPriority)priority ofTaskWithUUID:(nonnull NSUUID *)UUID;

If I look at PINRemoteImageDownloadTask it seems that you can only change the priority of progressive image task(?):

- (void)setPriority:(PINRemoteImageManagerPriority)priority
{
    [super setPriority:priority];
    if (@available(iOS 8.0, macOS 10.10, tvOS 9.0, watchOS 2.0, *)) {
        [self.lock lockWithBlock:^{
            if (self->_progressImage.dataTask) {
                self->_progressImage.dataTask.priority = dataTaskPriorityWithImageManagerPriority(priority);
                NSLog(@"Setting priority manually: %f", self->_progressImage.dataTask.priority);
                [self.manager.urlSessionTaskQueue setQueuePriority:priority forTask:self->_progressImage.dataTask];
            }
        }];
    }

If I am reading the code right, it looks like it's "impossible" to change the priority right now of a image download (that's non-progressive)?

I also would be curious on whether the priorities are always respected. Because of the additional call to set a priority (instead of directly setting it as part of download:), it makes it hard to reason whether the image task will actually get its priority bumped before the network call goes out.

Related issue: https://github.com/pinterest/PINRemoteImage/issues/262

garrettmoon commented 6 years ago

Yeah, I think this is actually a bug since I don't think task priority actually affects much once the request has been sent :/