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

Avoid excessive network requests when image fails to load #172

Closed
kurteous opened this issue Sep 16, 2022 · 4 comments
Closed

Avoid excessive network requests when image fails to load #172

kurteous opened this issue Sep 16, 2022 · 4 comments
Assignees

Comments

@kurteous
Copy link

We have a case where we may get a bad URL as input, and the image will fail to load. In this case, upon every recomposition GlideImage will try to reload the failing image. This is a lot of unnecessary network usage and churn.

Any ideas how to make it stop trying to load after the first failure? It doesn't look like Glide itself has this feature (maximum retries, for instance).

Thanks!

@skydoves
Copy link
Owner

@kurteous Hey, could you share the library version you use with me? Thanks!

@kurteous
Copy link
Author

I am using 1.5.2.

One approach is to remember load failure outside the GlideImage function call:

var failedToLoad by mutableStateOf(false)
...
if (!failedToLoad) {
   GlideImage(
      ...
      failure = {
         failedToLoad = true
      }
      ...
   )
}

Trying this, I see that a new instance of failedToLoad is created on occasion, wiping out whatever the saved state is and potentially allowing a new failing network call, which means (I think) that I need to hoist that state higher into something that's not subject to recomposition, like a view model. Or figure out why the recomposition is creating an entirely new instance of failedToLoad sometimes, which is probably just a problem with my compose code.

Anyway, thanks for your help!

@skydoves skydoves self-assigned this Sep 29, 2022
@skydoves
Copy link
Owner

skydoves commented Oct 1, 2022

@kurteous, Thanks for sharing your idea with me!
In 2.0.1-SNAPSHOT, recomposition performance was improved so It might work without the tricky solution you've suggested. Could you build with the snapshot version?

@skydoves
Copy link
Owner

Hi @kurteous, any updates from your side?

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

2 participants