feat: 优化共同群聊计数缓存

This commit is contained in:
kuaifan 2025-09-28 06:28:24 +08:00
parent b62c580d5e
commit 22b3598704
4 changed files with 74 additions and 4 deletions

View File

@ -107,6 +107,7 @@ export default {
showModal: false,
commonDialog: {
userid: null,
total: null,
list: [],
page: 1,
@ -182,9 +183,39 @@ export default {
loadCommonDialogCount() {
const target_userid = this.userData.userid;
if (this.commonDialog.userid !== target_userid) {
this.commonDialog.total = null;
const previousUserId = this.commonDialog.userid;
if (!target_userid) {
this.commonDialog = {
...this.commonDialog,
userid: target_userid || null,
total: null,
list: [],
page: 1,
has_more: false,
};
return;
}
if (previousUserId !== target_userid) {
this.commonDialog = {
...this.commonDialog,
userid: target_userid,
total: null,
list: [],
page: 1,
has_more: false,
};
}
const cacheMap = this.$store.state.dialogCommonCountCache || {};
const cached = cacheMap[String(target_userid)];
if (cached && typeof cached.total !== 'undefined') {
this.commonDialog = {
...this.commonDialog,
total: cached.total,
};
}
this.$store.dispatch('call', {
url: 'dialog/common/list',
data: {
@ -195,10 +226,19 @@ export default {
if (target_userid !== this.userData.userid) {
return
}
this.commonDialog = Object.assign(data, {
const parsedTotal = Number(data.total);
const total = Number.isNaN(parsedTotal) ? 0 : parsedTotal;
this.commonDialog = {
...this.commonDialog,
userid: target_userid,
total,
list: [],
page: 1,
has_more: false,
};
this.$store.commit('common/dialog/count/save', {
userid: target_userid,
total,
});
});
},

View File

@ -1140,6 +1140,7 @@ export default {
json: [
'userInfo',
'taskRelatedCache',
'dialogCommonCountCache',
]
};

View File

@ -30,6 +30,33 @@ export default {
$A.IDBSave("cacheUserBasic", state.cacheUserBasic, 600)
},
// 共同群聊
'common/dialog/count/save': function(state, {userid, total, updatedAt = Date.now()}) {
if (!userid) {
return;
}
const key = String(userid);
const cache = Object.assign({}, state.dialogCommonCountCache);
const parsedTotal = Number(total);
cache[key] = {
total: Number.isNaN(parsedTotal) ? 0 : parsedTotal,
updated_at: updatedAt,
};
state.dialogCommonCountCache = cache;
$A.IDBSave("dialogCommonCountCache", state.dialogCommonCountCache, 600);
},
'common/dialog/count/clear': function(state, userid) {
if (typeof userid === 'number' || typeof userid === 'string') {
const cache = Object.assign({}, state.dialogCommonCountCache);
delete cache[String(userid)];
state.dialogCommonCountCache = cache;
} else {
state.dialogCommonCountCache = {};
}
$A.IDBSave("dialogCommonCountCache", state.dialogCommonCountCache, 600);
},
// 消息管理
'message/push': function(state, data) {
state.dialogMsgs.push(data)
@ -65,7 +92,7 @@ export default {
$A.IDBSave("cacheTasks", state.cacheTasks, 600)
},
// taskContents
// 任务内容
'task/content/push': function(state, data) {
state.taskContents.push(data)
},
@ -78,6 +105,7 @@ export default {
}
},
// 任务关联
'task/related/save': function(state, {taskId, list, updatedAt = Date.now()}) {
const cache = Object.assign({}, state.taskRelatedCache);
cache[taskId] = {

View File

@ -147,6 +147,7 @@ export default {
dialogDroupWordChain: {},
dialogGroupVote: {},
dialogModalShow: false,
dialogCommonCountCache: {},
// 搜索关键词(主要用于移动端判断滑动返回)
messengerSearchKey: {dialog: '', contacts: ''},