diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java index c4fa492d4d..0fd85801fe 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java @@ -140,11 +140,10 @@ public class GitRepositoryUtil { private String getFileLastCommitId(ObjectId objectId, String filePath) throws Exception { Iterable logs = git.log().add(objectId).addPath(filePath).call(); - String returnStr = StringUtils.EMPTY; for (RevCommit rev : logs) { - returnStr = rev.getName(); + return rev.getName(); } - return returnStr; + return null; } private RevCommit getRevTreeByRepositoryAndCommitId(InMemoryRepository repo, ObjectId fileCommitId) throws Exception { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index 9e66be027f..bbaa744301 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -532,13 +532,16 @@ public class FileMetadataService { private void setFileVersionIsOld(FileMetadata oldFile, String operator) { //删除旧的预览文件 TempFileUtils.deleteTmpFile(oldFile.getId()); - //更新文件版本分支 + //通过refId批量更新 + FileMetadataExample example = new FileMetadataExample(); + example.createCriteria().andRefIdEqualTo(oldFile.getRefId()).andLatestEqualTo(true); + FileMetadata updateModel = new FileMetadata(); - updateModel.setId(oldFile.getId()); updateModel.setLatest(false); updateModel.setUpdateTime(System.currentTimeMillis()); updateModel.setUpdateUser(operator); - fileMetadataMapper.updateByPrimaryKeySelective(updateModel); + + fileMetadataMapper.updateByExampleSelective(updateModel, example); } private void genNewFileVersionByOldFile(FileMetadata oldFile, FileMetadata fileMetadata, String operator) { @@ -620,6 +623,7 @@ public class FileMetadataService { //获取fileMetadata以及可能存在的fileMetadataRepository FileMetadataExample example = new FileMetadataExample(); example.createCriteria().andRefIdEqualTo(fileMetadata.getRefId()); + example.setOrderByClause(" create_time DESC "); List fileMetadataList = fileMetadataMapper.selectByExample(example); List fileIdList = fileMetadataList.stream().map(FileMetadata::getId).toList(); FileMetadataRepositoryExample repositoryExample = new FileMetadataRepositoryExample();