perf: 优化通讯录刷新机制

This commit is contained in:
kuaifan 2022-06-13 16:17:47 +08:00
parent 11308829a6
commit be3fcb55fb
2 changed files with 43 additions and 1 deletions

View File

@ -350,6 +350,7 @@ class UsersController extends AbstractController
* - keys.no_project_id 不在指定项目ID
* @apiParam {Object} sorts 排序方式
* - sorts.az 按字母asc|desc
* @apiParam {Number} updated_time 在这个时间戳之后更新的
*
* @apiParam {Number} [take] 获取数量10-100
* @apiParam {Number} [page] 当前页,默认:1赋值分页模式take参数无效
@ -365,6 +366,7 @@ class UsersController extends AbstractController
//
$keys = Request::input('keys');
$sorts = Request::input('sorts');
$updatedTime = intval(Request::input('updated_time'));
$keys = is_array($keys) ? $keys : [];
$sorts = is_array($sorts) ? $sorts : [];
//
@ -379,6 +381,9 @@ class UsersController extends AbstractController
} elseif (intval($keys['disable']) == 2) {
$builder->whereNotNull("disable_at");
}
if ($updatedTime > 0) {
$builder->where("updated_at", ">=", Carbon::createFromTimestamp($updatedTime));
}
if (intval($keys['project_id']) > 0) {
$builder->whereIn('userid', function ($query) use ($keys) {
$query->select('userid')->from('project_users')->where('project_id', $keys['project_id']);

View File

@ -171,6 +171,7 @@ export default {
contactsData: null,
contactsCurrentPage: 1,
contactsHasMorePages: false,
contactsLastTime: 0,
operateItem: {},
operateStyles: {},
@ -346,7 +347,14 @@ export default {
tabActive: {
handler(val) {
if (val == 'contacts') {
this.contactsData === null && this.getContactsList(1);
if ($A.Time() - this.contactsLastTime > 24 * 3600) {
this.contactsData = null; // 24
}
if (this.contactsData === null) {
this.getContactsList(1);
} else {
this.updateContactsList(1000);
}
} else {
this.updateDialogs(1000);
}
@ -477,9 +485,38 @@ export default {
this.contactsHasMorePages = false;
}).finally(_ => {
this.contactsLoad--;
this.contactsLastTime = $A.Time()
});
},
updateContactsList(timeout) {
this.__updateContactsList && clearTimeout(this.__updateContactsList)
if (timeout > -1) {
this.__updateContactsList = setTimeout(_ => {
if (this.tabActive === 'contacts') {
this.$store.dispatch("call", {
url: 'users/search',
data: {
updated_time: this.contactsLastTime,
take: 100
},
}).then(({data}) => {
data.some((user) => {
const index = this.contactsData.findIndex(item => item.userid == user.userid);
if (index > -1) {
this.contactsData.splice(index, 1, user);
} else {
this.contactsData.push(user);
}
});
}).finally(_ => {
this.contactsLastTime = $A.Time()
});
}
}, timeout)
}
},
formatLastMsg(data) {
if ($A.isJson(data)) {
switch (data.type) {