mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-18 15:22:50 +00:00
feat: 优化共同群聊计数缓存
This commit is contained in:
parent
b62c580d5e
commit
22b3598704
@ -107,6 +107,7 @@ export default {
|
|||||||
showModal: false,
|
showModal: false,
|
||||||
|
|
||||||
commonDialog: {
|
commonDialog: {
|
||||||
|
userid: null,
|
||||||
total: null,
|
total: null,
|
||||||
list: [],
|
list: [],
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -182,9 +183,39 @@ export default {
|
|||||||
|
|
||||||
loadCommonDialogCount() {
|
loadCommonDialogCount() {
|
||||||
const target_userid = this.userData.userid;
|
const target_userid = this.userData.userid;
|
||||||
if (this.commonDialog.userid !== target_userid) {
|
const previousUserId = this.commonDialog.userid;
|
||||||
this.commonDialog.total = null;
|
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', {
|
this.$store.dispatch('call', {
|
||||||
url: 'dialog/common/list',
|
url: 'dialog/common/list',
|
||||||
data: {
|
data: {
|
||||||
@ -195,10 +226,19 @@ export default {
|
|||||||
if (target_userid !== this.userData.userid) {
|
if (target_userid !== this.userData.userid) {
|
||||||
return
|
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,
|
userid: target_userid,
|
||||||
|
total,
|
||||||
list: [],
|
list: [],
|
||||||
|
page: 1,
|
||||||
has_more: false,
|
has_more: false,
|
||||||
|
};
|
||||||
|
this.$store.commit('common/dialog/count/save', {
|
||||||
|
userid: target_userid,
|
||||||
|
total,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
1
resources/assets/js/store/actions.js
vendored
1
resources/assets/js/store/actions.js
vendored
@ -1140,6 +1140,7 @@ export default {
|
|||||||
json: [
|
json: [
|
||||||
'userInfo',
|
'userInfo',
|
||||||
'taskRelatedCache',
|
'taskRelatedCache',
|
||||||
|
'dialogCommonCountCache',
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
30
resources/assets/js/store/mutations.js
vendored
30
resources/assets/js/store/mutations.js
vendored
@ -30,6 +30,33 @@ export default {
|
|||||||
$A.IDBSave("cacheUserBasic", state.cacheUserBasic, 600)
|
$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) {
|
'message/push': function(state, data) {
|
||||||
state.dialogMsgs.push(data)
|
state.dialogMsgs.push(data)
|
||||||
@ -65,7 +92,7 @@ export default {
|
|||||||
$A.IDBSave("cacheTasks", state.cacheTasks, 600)
|
$A.IDBSave("cacheTasks", state.cacheTasks, 600)
|
||||||
},
|
},
|
||||||
|
|
||||||
// taskContents
|
// 任务内容
|
||||||
'task/content/push': function(state, data) {
|
'task/content/push': function(state, data) {
|
||||||
state.taskContents.push(data)
|
state.taskContents.push(data)
|
||||||
},
|
},
|
||||||
@ -78,6 +105,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 任务关联
|
||||||
'task/related/save': function(state, {taskId, list, updatedAt = Date.now()}) {
|
'task/related/save': function(state, {taskId, list, updatedAt = Date.now()}) {
|
||||||
const cache = Object.assign({}, state.taskRelatedCache);
|
const cache = Object.assign({}, state.taskRelatedCache);
|
||||||
cache[taskId] = {
|
cache[taskId] = {
|
||||||
|
|||||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -147,6 +147,7 @@ export default {
|
|||||||
dialogDroupWordChain: {},
|
dialogDroupWordChain: {},
|
||||||
dialogGroupVote: {},
|
dialogGroupVote: {},
|
||||||
dialogModalShow: false,
|
dialogModalShow: false,
|
||||||
|
dialogCommonCountCache: {},
|
||||||
|
|
||||||
// 搜索关键词(主要用于移动端判断滑动返回)
|
// 搜索关键词(主要用于移动端判断滑动返回)
|
||||||
messengerSearchKey: {dialog: '', contacts: ''},
|
messengerSearchKey: {dialog: '', contacts: ''},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user