debug:并发情况下,缓存多存很多信息

This commit is contained in:
磷叶 2025-02-28 09:07:09 +08:00
parent 2f0a51b5c8
commit 130a4a6cbf
3 changed files with 14 additions and 14 deletions

View File

@ -78,9 +78,9 @@ public class AttachClassifyServiceImpl implements AttachClassifyService
} else { } else {
attachClassify.setAncestors("0"); attachClassify.setAncestors("0");
} }
attachClassify.setCreateTime(DateUtils.getNowDate()); attachClassify.setCreateTime(DateUtils.getNowDate());
return transactionTemplate.execute(status -> { return transactionTemplate.execute(status -> {
int insert = attachClassifyMapper.insertAttachClassify(attachClassify); int insert = attachClassifyMapper.insertAttachClassify(attachClassify);
if (insert > 0) { if (insert > 0) {
@ -103,18 +103,18 @@ public class AttachClassifyServiceImpl implements AttachClassifyService
AttachClassifyVO newParentClassify = attachClassifyMapper.selectAttachClassifyById(attachClassify.getParentId()); AttachClassifyVO newParentClassify = attachClassifyMapper.selectAttachClassifyById(attachClassify.getParentId());
// 查询旧的分类信息 // 查询旧的分类信息
AttachClassifyVO oldClassify = attachClassifyMapper.selectAttachClassifyById(attachClassify.getId()); AttachClassifyVO oldClassify = attachClassifyMapper.selectAttachClassifyById(attachClassify.getId());
return transactionTemplate.execute(status -> { return transactionTemplate.execute(status -> {
if (newParentClassify != null && oldClassify != null) { if (newParentClassify != null && oldClassify != null) {
// 构建新的祖级列表 // 构建新的祖级列表
String newAncestors = newParentClassify.getAncestors() + "," + newParentClassify.getId(); String newAncestors = newParentClassify.getAncestors() + "," + newParentClassify.getId();
String oldAncestors = oldClassify.getAncestors(); String oldAncestors = oldClassify.getAncestors();
attachClassify.setAncestors(newAncestors); attachClassify.setAncestors(newAncestors);
// 更新子节点的祖级列表 // 更新子节点的祖级列表
updateChildrenAncestors(attachClassify.getId(), newAncestors, oldAncestors); updateChildrenAncestors(attachClassify.getId(), newAncestors, oldAncestors);
} }
int update = attachClassifyMapper.updateAttachClassify(attachClassify); int update = attachClassifyMapper.updateAttachClassify(attachClassify);
if (update > 0) { if (update > 0) {
clearCache(); clearCache();
@ -178,7 +178,7 @@ public class AttachClassifyServiceImpl implements AttachClassifyService
return result == null ? 0 : result; return result == null ? 0 : result;
} }
private int selectCountByParentIds(List<Long> parentIds) { private int selectCountByParentIds(List<Long> parentIds) {
if (CollectionUtils.isEmptyElement(parentIds)) { if (CollectionUtils.isEmptyElement(parentIds)) {
return 0; return 0;
} }
@ -194,12 +194,12 @@ public class AttachClassifyServiceImpl implements AttachClassifyService
@Override @Override
public List<AttachClassifyNameVO> selectAllNameList(){ public List<AttachClassifyNameVO> selectAllNameList(){
List<AttachClassifyNameVO> list = redisCache.getCacheList(CacheConstants.ATTACH_CLASSIFY_NAME_LIST); List<AttachClassifyNameVO> list = redisCache.getCacheObject(CacheConstants.ATTACH_CLASSIFY_NAME_LIST);
if(CollectionUtils.isEmptyElement(list)){ if(CollectionUtils.isEmptyElement(list)){
PageHelper.orderBy("bac.sort asc"); PageHelper.orderBy("bac.sort asc");
list = attachClassifyMapper.selectNameList(new AttachClassifyQuery()); list = attachClassifyMapper.selectNameList(new AttachClassifyQuery());
if (CollectionUtils.isNotEmptyElement(list)) { if (CollectionUtils.isNotEmptyElement(list)) {
redisCache.setCacheList(CacheConstants.ATTACH_CLASSIFY_NAME_LIST, list); redisCache.setCacheObject(CacheConstants.ATTACH_CLASSIFY_NAME_LIST, list);
} }
} }
return list; return list;

View File

@ -142,11 +142,11 @@ public class ProjectServiceImpl implements ProjectService
@Override @Override
public List<ProjectNameVO> selectAllNameList() { public List<ProjectNameVO> selectAllNameList() {
List<ProjectNameVO> list = redisCache.getCacheList(CacheConstants.PROJECT_NAME_LIST); List<ProjectNameVO> list = redisCache.getCacheObject(CacheConstants.PROJECT_NAME_LIST);
if (CollectionUtils.isEmptyElement(list)) { if (CollectionUtils.isEmptyElement(list)) {
list = projectMapper.selectNameList(new ProjectQuery()); list = projectMapper.selectNameList(new ProjectQuery());
if (CollectionUtils.isNotEmptyElement(list)) { if (CollectionUtils.isNotEmptyElement(list)) {
redisCache.setCacheList(CacheConstants.PROJECT_NAME_LIST, list); redisCache.setCacheObject(CacheConstants.PROJECT_NAME_LIST, list);
} }
} }
return list; return list;

View File

@ -302,7 +302,7 @@ public class UserServiceImpl implements UserService
return result == null ? 0 : result; return result == null ? 0 : result;
} }
void clearCache() { void clearCache() {
redisCache.deleteObject(CacheConstants.USER_NAME_LIST); redisCache.deleteObject(CacheConstants.USER_NAME_LIST);
} }
@ -425,7 +425,7 @@ public class UserServiceImpl implements UserService
public boolean updateUserAvatar(String userName, String avatar) public boolean updateUserAvatar(String userName, String avatar)
{ {
int rows = userMapper.updateUserAvatar(userName, avatar); int rows = userMapper.updateUserAvatar(userName, avatar);
if (rows > 0) { if (rows > 0) {
clearCache(); clearCache();
} }
@ -722,13 +722,13 @@ public class UserServiceImpl implements UserService
@Override @Override
public List<SysUserNameVO> selectAllUserNameList() { public List<SysUserNameVO> selectAllUserNameList() {
List<SysUserNameVO> list = redisCache.getCacheList(CacheConstants.USER_NAME_LIST); List<SysUserNameVO> list = redisCache.getCacheObject(CacheConstants.USER_NAME_LIST);
if (CollectionUtils.isEmptyElement(list)) { if (CollectionUtils.isEmptyElement(list)) {
SysUserQuery query = new SysUserQuery(); SysUserQuery query = new SysUserQuery();
query.setExcludeUserId(1L); query.setExcludeUserId(1L);
list = userMapper.selectNameList(query); list = userMapper.selectNameList(query);
if (CollectionUtils.isNotEmptyElement(list)) { if (CollectionUtils.isNotEmptyElement(list)) {
redisCache.setCacheList(CacheConstants.USER_NAME_LIST, list); redisCache.setCacheObject(CacheConstants.USER_NAME_LIST, list);
} }
} }
return list; return list;