fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Fresco requests same URI several times

Open SandyWangWei opened this issue 11 years ago • 6 comments

Hi ,I recently encountered a problem that Fresco repeat request with same URI.For example,there is a listview, refresh it several times the problem happens, the requests of some pictures are send repeatly.The following is the request I catch. image Can you help me?

SandyWangWei avatar Sep 02 '15 05:09 SandyWangWei

Actually I think It's reasonable to load a image for only once ~~~It wastes resource to send several requests for the same image.So I wonder weather there a method to avoid request same image.

SandyWangWei avatar Sep 02 '15 13:09 SandyWangWei

You are absolutely right in that this should not happen. We have a logic in place that should prevent that from happening, but there may be a bug. Can you provide some more information please?

  • How/where do you initialize Fresco?
  • What do you mean by refreshing the listview? Do you mean Adapter.dataSetChanged or something else?
  • Can you please provide a verbose logcat: adb logcat -v threadtime | grep -iE 'LoggingListener|AbstractDraweeController'

plamenko avatar Sep 03 '15 16:09 plamenko

I simulated the situation that I had met. Uri1,Uri2,Uri3 are different images, in my project it may happen that the list may use notifyDataSetChanged() many times at same time.So I simulated the situation ,you will find it will request the same uri several times. image

Try the following codes:

public class MainActivity extends Activity {
    SimpleDraweeView imageTest,imageTest2,imageTest3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Fresco.initialize(this);
        setContentView(R.layout.activity_main);


        imageTest2=(SimpleDraweeView)findViewById(R.id.user_avator1);
        imageTest=(SimpleDraweeView)findViewById(R.id.user_avator);
        imageTest3=(SimpleDraweeView)findViewById(R.id.user_avator2);


        final Uri uri1 = Uri.parse("http://pic7.qiyipic.com/image/20150427/c3/9f/a_100011875_m_601_284_160.jpg");
        final Uri uri2 = Uri.parse("http://pic7.qiyipic.com/image/20150213/b2/aa/a_100010483_m_601_284_160.jpg");
        final Uri uri3 = Uri.parse("http://pic1.qiyipic.com/image/20150720/76/18/a_100013208_m_601_m5_284_160.jpg");

        Button btn=(Button)findViewById(R.id.button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for(int i=0;i<40;i++) {
                    imageTest2.setImageURI(uri1);
                    imageTest.setImageURI(uri2);
                    imageTest3.setImageURI(uri3);


                    imageTest3.setImageURI(uri2);
                    imageTest2.setImageURI(uri3);
                    imageTest.setImageURI(uri1);
                }
            }
        });
    }
}

SandyWangWei avatar Sep 05 '15 02:09 SandyWangWei

Could you tell me the where is logic to avoid repeat request ,not the cache~The premise is that the picture has not yet requested successfully.

SandyWangWei avatar Sep 05 '15 03:09 SandyWangWei

This ought to be blocked by the EncodedMemoryCacheMultiplexProducer.

We're cleaning up long-untouched issues so I'm closing this one.

If you think this is still an issue, feel free to comment and we can re-open.

kirwan avatar Sep 04 '17 09:09 kirwan

I also encountered this problem. When the image is downloading I close the activity, then reopen it, the image will download twice. Also, in RecyclerView when I scroll the list up and down quickly, some Images will download several times. This is a demo for this bug. https://github.com/binwin20/frescoDemo

realjustinwu avatar Apr 14 '18 05:04 realjustinwu