mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Improve commits page performance
This commit is contained in:
parent
a3950f8c7e
commit
e740c37fad
@ -84,7 +84,10 @@ public class BlameCommand extends GitCommand<Collection<BlameBlock>> {
|
||||
|
||||
String cacheKey = commitHash + ":" + file + ":" + (range!=null?range.toString():"");
|
||||
|
||||
Collection<BlameBlock> cached = cache.get(cacheKey);
|
||||
Collection<BlameBlock> cached;
|
||||
synchronized (cache) {
|
||||
cached = cache.get(cacheKey);
|
||||
}
|
||||
if (cached != null)
|
||||
return cached;
|
||||
|
||||
@ -181,8 +184,9 @@ public class BlameCommand extends GitCommand<Collection<BlameBlock>> {
|
||||
block.getRanges().add(new LinearRange(beginLine.get(), endLine.get()-1));
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis()-time > CACHE_THRESHOLD)
|
||||
if (System.currentTimeMillis()-time > CACHE_THRESHOLD) synchronized (cache) {
|
||||
cache.put(cacheKey, blocks.values());
|
||||
}
|
||||
|
||||
return blocks.values();
|
||||
}
|
||||
|
||||
@ -45,6 +45,8 @@ import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.apache.commons.collections4.map.ReferenceMap;
|
||||
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.shiro.authz.Permission;
|
||||
import org.apache.tika.mime.MediaType;
|
||||
@ -246,7 +248,10 @@ public class Project extends AbstractEntity {
|
||||
public static void pop() {
|
||||
stack.get().pop();
|
||||
}
|
||||
|
||||
|
||||
private static final ReferenceMap<ObjectId, Optional<BuildSpec>> buildSpecCache =
|
||||
new ReferenceMap<>(ReferenceStrength.HARD, ReferenceStrength.SOFT);
|
||||
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
@JoinColumn(nullable=true)
|
||||
@Api(description="Represents the project from which this project is forked. Remove this property if "
|
||||
@ -387,8 +392,6 @@ public class Project extends AbstractEntity {
|
||||
|
||||
private transient Map<String, Optional<ObjectId>> objectIdCache;
|
||||
|
||||
private transient Map<ObjectId, Optional<BuildSpec>> buildSpecCache;
|
||||
|
||||
private transient Map<ObjectId, Map<String, Collection<StatusInfo>>> commitStatusCache;
|
||||
|
||||
private transient Map<ObjectId, Optional<RevCommit>> commitCache;
|
||||
@ -858,9 +861,10 @@ public class Project extends AbstractEntity {
|
||||
*/
|
||||
@Nullable
|
||||
public BuildSpec getBuildSpec(ObjectId commitId) {
|
||||
if (buildSpecCache == null)
|
||||
buildSpecCache = new HashMap<>();
|
||||
Optional<BuildSpec> buildSpec = buildSpecCache.get(commitId);
|
||||
Optional<BuildSpec> buildSpec;
|
||||
synchronized (buildSpecCache) {
|
||||
buildSpec = buildSpecCache.get(commitId);
|
||||
}
|
||||
if (buildSpec == null) {
|
||||
Blob blob = getBlob(new BlobIdent(commitId.name(), BuildSpec.BLOB_PATH, FileMode.TYPE_FILE), false);
|
||||
if (blob != null) {
|
||||
@ -872,7 +876,9 @@ public class Project extends AbstractEntity {
|
||||
else
|
||||
buildSpec = Optional.absent();
|
||||
}
|
||||
buildSpecCache.put(commitId, buildSpec);
|
||||
synchronized (buildSpecCache) {
|
||||
buildSpecCache.put(commitId, buildSpec);
|
||||
}
|
||||
}
|
||||
return buildSpec.orNull();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user