Skip to content

Commit

Permalink
fix: 修复重建索引失败时会覆盖博客文章的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed May 8, 2024
1 parent 1b57b9c commit 870d11c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/jmal/clouddisk/service/impl/SettingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -234,6 +235,11 @@ private void createFile(Path file) {
commonFileService.createFile(username, file.toFile(), null, null);
} catch (Exception e) {
log.error("{}{}", e.getMessage(), file, e);
FileDocument fileDocument = commonFileService.getFileDocument(username, file.toFile().getAbsolutePath());
if (fileDocument != null) {
// 需要移除删除标记
removeDeleteFlagOfDoc(fileDocument.getId());
}
} finally {
if (totalCount > 0) {
if (processCount.get() <= 2) {
Expand All @@ -250,6 +256,18 @@ private void createFile(Path file) {
}
}

/**
* 移除删除标记
* @param fileId fileId
*/
public void removeDeleteFlagOfDoc(String fileId) {
Query query = new Query();
query.addCriteria(Criteria.where("_id").is(fileId));
Update update = new Update();
update.unset("delete");
mongoTemplate.updateMulti(query, update, CommonFileService.COLLECTION_NAME);
}

private static class FileCountVisitor extends SimpleFileVisitor<Path> {
private final AtomicLong count = new AtomicLong(0);

Expand Down

0 comments on commit 870d11c

Please sign in to comment.