[代码完善](v2.5): update menu、dept cache

close https://github.com/elunez/eladmin/issues/468
pull/482/head
ZhengJie 2020-09-06 17:19:57 +08:00
parent c680ec4e81
commit a0a1283970
2 changed files with 6 additions and 19 deletions

View File

@ -96,7 +96,6 @@ public class DeptServiceImpl implements DeptService {
}
@Override
@Cacheable(key = "'pid:' + #p0")
public List<Dept> findByPid(long pid) {
return deptRepository.findByPid(pid);
}
@ -113,7 +112,6 @@ public class DeptServiceImpl implements DeptService {
// 计算子节点数目
resources.setSubCount(0);
// 清理缓存
redisUtils.del("dept::pid:" + (resources.getPid() == null ? 0 : resources.getPid()));
updateSubCnt(resources.getPid());
}
@ -134,7 +132,7 @@ public class DeptServiceImpl implements DeptService {
updateSubCnt(oldPid);
updateSubCnt(newPid);
// 清理缓存
delCaches(resources.getId(), oldPid, newPid);
delCaches(resources.getId());
}
@Override
@ -142,7 +140,7 @@ public class DeptServiceImpl implements DeptService {
public void delete(Set<DeptDto> deptDtos) {
for (DeptDto deptDto : deptDtos) {
// 清理缓存
delCaches(deptDto.getId(), deptDto.getPid(), null);
delCaches(deptDto.getId());
deptRepository.deleteById(deptDto.getId());
updateSubCnt(deptDto.getPid());
}
@ -273,15 +271,11 @@ public class DeptServiceImpl implements DeptService {
/**
*
* @param id /
* @param oldPid /
* @param newPid /
*/
public void delCaches(Long id, Long oldPid, Long newPid){
public void delCaches(Long id){
List<User> users = userRepository.findByDeptRoleId(id);
// 删除数据权限
redisUtils.delByKeys("data::user:",users.stream().map(User::getId).collect(Collectors.toSet()));
redisUtils.del("dept::id:" + id);
redisUtils.del("dept::pid:" + (oldPid == null ? 0 : oldPid));
redisUtils.del("dept::pid:" + (newPid == null ? 0 : newPid));
}
}

View File

@ -128,7 +128,6 @@ public class MenuServiceImpl implements MenuService {
resources.setSubCount(0);
// 更新父节点菜单数目
updateSubCnt(resources.getPid());
redisUtils.del("menu::pid:" + (resources.getPid() == null ? 0 : resources.getPid()));
}
@Override
@ -183,7 +182,7 @@ public class MenuServiceImpl implements MenuService {
updateSubCnt(oldPid);
updateSubCnt(newPid);
// 清理缓存
delCaches(resources.getId(), oldPid, newPid);
delCaches(resources.getId());
}
@Override
@ -204,7 +203,7 @@ public class MenuServiceImpl implements MenuService {
public void delete(Set<Menu> menuSet) {
for (Menu menu : menuSet) {
// 清理缓存
delCaches(menu.getId(), menu.getPid(), null);
delCaches(menu.getId());
roleService.untiedMenu(menu.getId());
menuRepository.deleteById(menu.getId());
updateSubCnt(menu.getPid());
@ -212,7 +211,6 @@ public class MenuServiceImpl implements MenuService {
}
@Override
@Cacheable(key = "'pid:' + #p0")
public List<MenuDto> getMenus(Long pid) {
List<Menu> menus;
if(pid != null && !pid.equals(0L)){
@ -341,19 +339,14 @@ public class MenuServiceImpl implements MenuService {
/**
*
* @param id ID
* @param oldPid ID
* @param newPid ID
*/
public void delCaches(Long id, Long oldPid, Long newPid){
public void delCaches(Long id){
List<User> users = userRepository.findByMenuId(id);
redisUtils.del("menu::id:" +id);
redisUtils.delByKeys("menu::user:",users.stream().map(User::getId).collect(Collectors.toSet()));
redisUtils.del("menu::pid:" + (oldPid == null ? 0 : oldPid));
redisUtils.del("menu::pid:" + (newPid == null ? 0 : newPid));
// 清除 Role 缓存
List<Role> roles = roleService.findInMenuId(new ArrayList<Long>(){{
add(id);
add(newPid == null ? 0 : newPid);
}});
redisUtils.delByKeys("role::id:",roles.stream().map(Role::getId).collect(Collectors.toSet()));
}