mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] calculate hash lazily in loading details
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.intellij.vcs.log.data;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -9,6 +10,7 @@ import com.intellij.util.ThrowableConsumer;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsLogHashMap;
|
||||
import com.intellij.vcs.log.VcsLogProvider;
|
||||
import com.intellij.vcs.log.VcsShortCommitDetails;
|
||||
@@ -132,9 +134,15 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
|
||||
|
||||
// fill the cache with temporary "Loading" values to avoid producing queries for each commit that has not been cached yet,
|
||||
// even if it will be loaded within a previous query
|
||||
for (int commitId : hashes) {
|
||||
for (final int commitId : hashes) {
|
||||
if (!myCache.isKeyCached(commitId)) {
|
||||
myCache.put(commitId, (T)new LoadingDetails(myHashMap.getHash(commitId), taskNumber, root));
|
||||
myCache.put(commitId, (T)new LoadingDetails(new Computable<Hash>(){
|
||||
|
||||
@Override
|
||||
public Hash compute() {
|
||||
return myHashMap.getHash(commitId);
|
||||
}
|
||||
}, taskNumber, root));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.vcs.log.data;
|
||||
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -7,6 +8,7 @@ import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.impl.VcsChangesLazilyParsedDetails;
|
||||
import com.intellij.vcs.log.impl.VcsUserImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -23,8 +25,8 @@ public class LoadingDetails extends VcsChangesLazilyParsedDetails {
|
||||
|
||||
private final long myLoadingTaskIndex;
|
||||
|
||||
public LoadingDetails(@NotNull Hash hash, long loadingTaskIndex, @NotNull VirtualFile root) {
|
||||
super(hash, Collections.<Hash>emptyList(), -1, root, "Loading...", STUB_USER, "", STUB_USER, -1,
|
||||
public LoadingDetails(@NotNull Computable<Hash> computableHash, long loadingTaskIndex, @NotNull VirtualFile root) {
|
||||
super(new LazyHash(computableHash), Collections.<Hash>emptyList(), -1, root, "Loading...", STUB_USER, "", STUB_USER, -1,
|
||||
new ThrowableComputable<Collection<Change>, Exception>() {
|
||||
@Override
|
||||
public Collection<Change> compute() throws Exception {
|
||||
@@ -34,8 +36,37 @@ public class LoadingDetails extends VcsChangesLazilyParsedDetails {
|
||||
myLoadingTaskIndex = loadingTaskIndex;
|
||||
}
|
||||
|
||||
|
||||
public long getLoadingTaskIndex() {
|
||||
return myLoadingTaskIndex;
|
||||
}
|
||||
|
||||
private static class LazyHash implements Hash {
|
||||
@NotNull
|
||||
private final Computable<Hash> myComputableHash;
|
||||
@Nullable
|
||||
private volatile Hash myHash;
|
||||
|
||||
public LazyHash(@NotNull Computable<Hash> computableHash) {
|
||||
myComputableHash = computableHash;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String asString() {
|
||||
if (myHash == null) {
|
||||
myHash = myComputableHash.compute();
|
||||
}
|
||||
return myHash.asString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toShortString() {
|
||||
if (myHash == null) {
|
||||
myHash = myComputableHash.compute();
|
||||
}
|
||||
return myHash.toShortString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user