提交 7427a493 编写于 作者: S Sam Judd

Avoid expensive synchronization in MultiModelLoader and work around caching bug.

上级 c28837be
......@@ -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();
......@@ -48,9 +50,12 @@ class ResourceCacheGenerator implements DataFetcherGenerator,
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++;
......
......@@ -80,7 +80,6 @@ class MultiModelLoader<Model, Data> implements ModelLoader<Model, Data> {
private DataCallback<? super Data> callback;
@Nullable
private List<Throwable> exceptions;
private boolean isCancelled;
MultiFetcher(
@NonNull List<DataFetcher<Data>> fetchers,
......@@ -113,7 +112,6 @@ class MultiModelLoader<Model, Data> implements ModelLoader<Model, Data> {
@Override
public void cancel() {
isCancelled = true;
for (DataFetcher<Data> fetcher : fetchers) {
fetcher.cancel();
}
......@@ -133,10 +131,6 @@ class MultiModelLoader<Model, Data> implements ModelLoader<Model, Data> {
@Override
public void onDataReady(@Nullable Data data) {
if (isCancelled) {
return;
}
if (data != null) {
callback.onDataReady(data);
} else {
......@@ -146,19 +140,11 @@ class MultiModelLoader<Model, Data> implements ModelLoader<Model, 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册