Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Priority of download-dataTask after it started #73

Closed
mheicke opened this issue Jul 1, 2015 · 10 comments
Closed

Changing Priority of download-dataTask after it started #73

mheicke opened this issue Jul 1, 2015 · 10 comments
Milestone

Comments

@mheicke
Copy link

mheicke commented Jul 1, 2015

Hi,
since I prefetch a lot of images, but want to show a couple of images as fast as possible, I just looked into prioritization of Kingfisher. Looks quite good to me, besides one point: it's not possible to change the priority of a download, once it's started.

As an example: I start to download the images cat[1-100].png and dog[1-100].png. They are all priorized as low since its only prefetching. Now I open the cat view which has a tableView with cat images. So I want to set a couple of images (of the visible cells) via UIImageViews kf_setImageWithURL. Since there are 200 images currently downloading, I need a higher prioritization for the images cat1.png - cat5.png.

But since they are part of the batch download of the prefetching, their url is already in self.fetchLoads in ImageDownloader and hence the started-closure is not called again in line 214 and "task.priority" is not changed to default, although the options dictionary in the downloadImageWithURL-call does not contain the lowPriority option.

A solution could be to attach the downloadTask to the ImageFetchLoad. In this case, it would be also possible to provide auto-priorisation (the more callbacks are attached to the ImageFetchLoad, the higher the priority could be. Some rewrite of ImageDownloader would be needed.

What do you think?

Best regards,
Matt

@schickling
Copy link

This would be a huge improvement! 👍

@schickling
Copy link

Also is there a reason for just toggling between NSURLSessionTaskPriorityLow and NSURLSessionTaskPriorityDefault? The priority parameter is a float ranging from 0 to 1. This flexibility shouldn't be hidden.

@schickling
Copy link

screen shot 2016-01-02 at 12 25 26

@ejoebstl
Copy link

ejoebstl commented Jan 2, 2016

Yes, I a agree. That feature would be very useful.

@onevcat
Copy link
Owner

onevcat commented Jan 2, 2016

The original implementation hides the Float detail and tries to make things simpler. But I guess it is reasonable to give users more control on it by setting a value for the priority. However, changes on it might means API breaking. I will take a look to see if we could mark current lowPriority option as deprecated and introduce a new way to set initial priority for a download task soon.

And for changing the priority on air when downloading, the downloader APIs (as well as the image view extension APIs) are returning a image task. We could just expose the priority property of task object to support changing it after download task started. It will be implemented soon in next major version.

@schickling
Copy link

Really looking forward to this improvement!

@onevcat onevcat added this to the Version 2.0.0 milestone Jan 5, 2016
@onevcat
Copy link
Owner

onevcat commented Jan 6, 2016

Implemented in #194

@schickling
Copy link

Nice! Can't wait until it gets released!

@onevcat
Copy link
Owner

onevcat commented Jan 13, 2016

It will be released later as a part of version 2.0.0.

@onevcat onevcat closed this as completed Jan 13, 2016
@schickling
Copy link

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants