Skip to content

Commit

Permalink
Merge pull request #169 from jamebal/develop
Browse files Browse the repository at this point in the history
perf: 优化初次启动时初始化角色、菜单
  • Loading branch information
jamebal authored Nov 4, 2024
2 parents 9e1395f + acfd8de commit c852c36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public class RebuildIndexTaskService {
public void init() {
// 启动时检测是否存在菜单,不存在则初始化
if (!menuService.existsMenu()) {
log.info("初始化角色、菜单!");
menuService.initMenus();
roleService.initRoles();
}
Expand Down Expand Up @@ -263,7 +262,7 @@ public void run() {
public void rebuildingIndexCompleted() {
if (!hasUnIndexedTasks() && NOT_INDEX_TASK_SIZE.get() > 0) {
setPercentMap(100d, 100d);
log.info("重建索引完成, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", INDEXED_TASK_SIZE, NOT_INDEX_TASK_SIZE);
log.debug("重建索引完成, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", INDEXED_TASK_SIZE, NOT_INDEX_TASK_SIZE);
restIndexedTasks();
pushMessage();
}
Expand Down Expand Up @@ -467,7 +466,7 @@ private void setPercentMap(Double syncPercent, Double indexingPercent) {

private void pushMessage() {
commonFileService.pushMessage(getRecipient(null), PERCENT_MAP, RebuildIndexTaskService.MSG_SYNCED);
log.info("推送消息: {}, isSyncFile: {}, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", PERCENT_MAP, isSyncFile(), INDEXED_TASK_SIZE.get(), NOT_INDEX_TASK_SIZE.get());
log.debug("推送消息: {}, isSyncFile: {}, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", PERCENT_MAP, isSyncFile(), INDEXED_TASK_SIZE.get(), NOT_INDEX_TASK_SIZE.get());
}

private class FileCountVisitor extends SimpleFileVisitor<Path> {
Expand Down
38 changes: 14 additions & 24 deletions src/main/java/com/jmal/clouddisk/service/impl/MenuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.jmal.clouddisk.model.rbac.MenuDTO;
import com.jmal.clouddisk.service.IUserService;
import com.jmal.clouddisk.util.*;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -52,25 +51,6 @@ public class MenuService {
@Autowired
private MessageUtil messageUtil;

@PostConstruct
public void init() {
// 启动时更新菜单
ThreadUtil.execute(() -> {
TimeInterval timeInterval = new TimeInterval();
List<MenuDO> menuDOList = getMenuDOListByConfigJSON();
if (menuDOList.isEmpty()) return;
menuDOList.parallelStream().forEach(menuDO -> {
Query query = new Query();
query.addCriteria(Criteria.where("_id").is(menuDO.getId()));
boolean exists = mongoTemplate.exists(query, COLLECTION_NAME);
if (!exists) {
mongoTemplate.insert(menuDO);
}
});
log.info("更新菜单, 耗时:{}ms", timeInterval.intervalMs());
});
}

/***
* 菜单树
* @param queryDTO QueryMenuDTO
Expand Down Expand Up @@ -263,10 +243,20 @@ public List<String> getAuthorities(List<String> menuIdList) {
* 初始化菜单数据
*/
public void initMenus() {
List<MenuDO> menuDOList = getMenuDOListByConfigJSON();
if (menuDOList.isEmpty()) return;
mongoTemplate.dropCollection(COLLECTION_NAME);
mongoTemplate.insertAll(menuDOList);
ThreadUtil.execute(() -> {
TimeInterval timeInterval = new TimeInterval();
List<MenuDO> menuDOList = getMenuDOListByConfigJSON();
if (menuDOList.isEmpty()) return;
menuDOList.parallelStream().forEach(menuDO -> {
Query query = new Query();
query.addCriteria(Criteria.where("_id").is(menuDO.getId()));
boolean exists = mongoTemplate.exists(query, COLLECTION_NAME);
if (!exists) {
mongoTemplate.insert(menuDO);
}
});
log.info("更新菜单, 耗时:{}ms", timeInterval.intervalMs());
});
}

/**
Expand Down

0 comments on commit c852c36

Please sign in to comment.