refactor(性能测试): 性能测试Git下载采用流式下载法
This commit is contained in:
parent
1e91f20744
commit
6ffac87d3f
|
@ -10,7 +10,6 @@ import io.metersphere.metadata.vo.RepositoryRequest;
|
|||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -47,7 +46,10 @@ public class GitFileRepository implements FileRepository {
|
|||
|
||||
@Override
|
||||
public InputStream getFileAsStream(FileRequest request) throws Exception {
|
||||
return new ByteArrayInputStream(getFile(request));
|
||||
RemoteFileAttachInfo gitFileInfo = request.getFileAttachInfo();
|
||||
GitRepositoryUtil repositoryUtils = new GitRepositoryUtil(
|
||||
gitFileInfo.getRepositoryPath(), gitFileInfo.getUserName(), gitFileInfo.getToken());
|
||||
return repositoryUtils.getFileAsStream(gitFileInfo.getCommitId(), gitFileInfo.getFilePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
|||
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -214,4 +215,19 @@ public class GitRepositoryUtil {
|
|||
return returnList;
|
||||
|
||||
}
|
||||
|
||||
public InputStream getFileAsStream(String commitId, String filePath) throws Exception {
|
||||
InMemoryRepository repo = this.getGitRepositoryInMemory(this.repositoryUrl, this.userName, this.token);
|
||||
ObjectId fileCommitObjectId = repo.resolve(commitId);
|
||||
RevWalk revWalk = new RevWalk(repo);
|
||||
RevCommit commit = revWalk.parseCommit(fileCommitObjectId);
|
||||
RevTree tree = commit.getTree();
|
||||
TreeWalk treeWalk = new TreeWalk(repo);
|
||||
treeWalk.addTree(tree);
|
||||
treeWalk.setRecursive(true);
|
||||
treeWalk.setFilter(PathFilter.create(filePath));
|
||||
ObjectId objectId = treeWalk.getObjectId(0);
|
||||
ObjectLoader loader = repo.open(objectId);
|
||||
return loader.openStream();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue