Skip to content

Commit

Permalink
Avoid expensive synchronization in MultiModelLoader and work around c…
Browse files Browse the repository at this point in the history
…aching bug.
  • Loading branch information
sjudd committed Mar 12, 2018
1 parent c28837b commit 7427a49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ResourceCacheGenerator implements DataFetcherGenerator,
this.cb = cb;
}

// See TODO below.
@SuppressWarnings("PMD.CollapsibleIfStatements")
@Override
public boolean startNext() {
List<Key> sourceIds = helper.getCacheKeys();
Expand All @@ -48,9 +50,12 @@ public boolean startNext() {
if (File.class.equals(helper.getTranscodeClass())) {
return false;
}
throw new IllegalStateException(
"Failed to find any load path from " + helper.getModelClass() + " to "
+ helper.getTranscodeClass());
// TODO(b/73882030): This case gets triggered when it shouldn't. With this assertion it causes
// all loads to fail. Without this assertion it causes loads to miss the disk cache
// unnecessarily
// throw new IllegalStateException(
// "Failed to find any load path from " + helper.getModelClass() + " to "
// + helper.getTranscodeClass());
}
while (modelLoaders == null || !hasNextModelLoader()) {
resourceClassIndex++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ static class MultiFetcher<Data> implements DataFetcher<Data>, DataCallback<Data>
private DataCallback<? super Data> callback;
@Nullable
private List<Throwable> exceptions;
private boolean isCancelled;

MultiFetcher(
@NonNull List<DataFetcher<Data>> fetchers,
Expand Down Expand Up @@ -113,7 +112,6 @@ public void cleanup() {

@Override
public void cancel() {
isCancelled = true;
for (DataFetcher<Data> fetcher : fetchers) {
fetcher.cancel();
}
Expand All @@ -133,10 +131,6 @@ public DataSource getDataSource() {

@Override
public void onDataReady(@Nullable Data data) {
if (isCancelled) {
return;
}

if (data != null) {
callback.onDataReady(data);
} else {
Expand All @@ -146,19 +140,11 @@ public void onDataReady(@Nullable Data data) {

@Override
public void onLoadFailed(@NonNull Exception e) {
if (isCancelled) {
return;
}

Preconditions.checkNotNull(exceptions).add(e);
startNextOrFail();
}

private void startNextOrFail() {
if (isCancelled) {
return;
}

if (currentIndex < fetchers.size() - 1) {
currentIndex++;
loadData(priority, callback);
Expand Down

0 comments on commit 7427a49

Please sign in to comment.