From a1e3fa281baa3bc13fddd8160fedbd6c96cbf6b0 Mon Sep 17 00:00:00 2001 From: judds Date: Thu, 30 Nov 2017 12:18:02 -0800 Subject: [PATCH] Only restart full request when restarting requests with thumbnails. When thumbnail requests finish after full requests complete, we discard the thumbnail's resource to decrease memory usage and we set the thumbnails status to complete. When requests are restarted after they complete, we just call onLoadComplete with whatever resource they had previously. As a result, thumbnail requests that completed after full requests were calling onLoadComplete(null), causing spammy error logs and potentially undesireable calls to onLoadFailed. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177489960 --- .../request/ThumbnailRequestCoordinator.java | 4 ++- .../ThumbnailRequestCoordinatorTest.java | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java b/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java index d0d89fea3a..ec172f8486 100644 --- a/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java +++ b/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java @@ -110,7 +110,9 @@ private boolean parentIsAnyResourceSet() { @Override public void begin() { isRunning = true; - if (!thumb.isRunning()) { + // If the request has completed previously, there's no need to restart both the full and the + // thumb, we can just restart the full. + if (!full.isComplete() && !thumb.isRunning()) { thumb.begin(); } if (isRunning && !full.isRunning()) { diff --git a/library/src/test/java/com/bumptech/glide/request/ThumbnailRequestCoordinatorTest.java b/library/src/test/java/com/bumptech/glide/request/ThumbnailRequestCoordinatorTest.java index 525d6dbc18..4850a2d01c 100644 --- a/library/src/test/java/com/bumptech/glide/request/ThumbnailRequestCoordinatorTest.java +++ b/library/src/test/java/com/bumptech/glide/request/ThumbnailRequestCoordinatorTest.java @@ -85,6 +85,33 @@ public void testDoesNotStartThumbOnRunIfRunning() { verify(thumb, never()).begin(); } + @Test + public void begin_whenFullIsComplete_startsFull() { + when(full.isComplete()).thenReturn(true); + + coordinator.begin(); + + verify(full).begin(); + } + + @Test + public void begin_whenFullIsComplete_doesNotBeginThumb() { + when(full.isComplete()).thenReturn(true); + + coordinator.begin(); + + verify(thumb, never()).begin(); + } + + @Test + public void begin_whenFullIsComplete_doesNotSetRunning() { + when(full.isComplete()).thenReturn(true); + + coordinator.begin(); + + assertThat(coordinator.isRunning()).isFalse(); + } + @Test public void testDoesNotStartFullIfClearedByThumb() { doAnswer(new Answer() {