mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-07 09:57:37 +00:00
perf: 优化ws连接机制
This commit is contained in:
parent
50a6b91a7e
commit
db5bcfb683
@ -81,19 +81,6 @@ class User extends AbstractModel
|
||||
// 基本信息的字段
|
||||
public static $basicField = ['userid', 'email', 'nickname', 'profession', 'department', 'userimg', 'bot', 'az', 'pinyin', 'line_at', 'disable_at'];
|
||||
|
||||
/**
|
||||
* 更新数据校验
|
||||
* @param array $param
|
||||
*/
|
||||
public function updateInstance(array $param)
|
||||
{
|
||||
parent::updateInstance($param);
|
||||
//
|
||||
if (isset($param['line_at']) && $this->userid) {
|
||||
Cache::put("User::online:" . $this->userid, time(), Carbon::now()->addSeconds(30));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
* @param $value
|
||||
@ -163,7 +150,7 @@ class User extends AbstractModel
|
||||
*/
|
||||
public function getOnlineStatus()
|
||||
{
|
||||
$online = $this->bot || intval(Cache::get("User::online:" . $this->userid, 0)) > 0;
|
||||
$online = $this->bot || Cache::get("User::online:" . $this->userid) === "on";
|
||||
if ($online) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1537,10 +1537,8 @@ class Base
|
||||
*/
|
||||
public static function jsonEcho($param)
|
||||
{
|
||||
global $_GPC;
|
||||
//
|
||||
$json = json_encode($param);
|
||||
$callback = $_GPC['callback'];
|
||||
$callback = Request::input('callback');
|
||||
if ($callback) {
|
||||
return $callback . '(' . $json . ')';
|
||||
} else {
|
||||
@ -1557,11 +1555,11 @@ class Base
|
||||
*/
|
||||
public static function retSuccess($msg, $data = [], $ret = 1)
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'ret' => $ret,
|
||||
'msg' => self::Lang($msg),
|
||||
'data' => $data
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1573,11 +1571,11 @@ class Base
|
||||
*/
|
||||
public static function retError($msg, $data = [], $ret = 0)
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'ret' => $ret,
|
||||
'msg' => self::Lang($msg),
|
||||
'data' => $data
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -191,13 +191,15 @@ class WebSocketService implements WebSocketHandlerInterface
|
||||
*/
|
||||
private function saveUser($fd, $userid)
|
||||
{
|
||||
Cache::put("User::fd:" . $fd, "on", Carbon::now()->addDay());
|
||||
Cache::put("User::online:" . $userid, "on", Carbon::now()->addDay());
|
||||
//
|
||||
WebSocket::updateInsert([
|
||||
'key' => md5($fd . '@' . $userid)
|
||||
], [
|
||||
'fd' => $fd,
|
||||
'userid' => $userid,
|
||||
]);
|
||||
Cache::put("User::online:" . $userid, time(), Carbon::now()->addSeconds(30));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,6 +208,8 @@ class WebSocketService implements WebSocketHandlerInterface
|
||||
*/
|
||||
private function deleteUser($fd)
|
||||
{
|
||||
Cache::forget("User::fd:" . $fd);
|
||||
//
|
||||
$array = [];
|
||||
WebSocket::whereFd($fd)->chunk(10, function($list) use (&$array) {
|
||||
/** @var WebSocket $item */
|
||||
@ -216,6 +220,7 @@ class WebSocketService implements WebSocketHandlerInterface
|
||||
User::whereUserid($item->userid)->update([
|
||||
'line_at' => Carbon::now()
|
||||
]);
|
||||
Cache::forget("User::online:" . $item->userid);
|
||||
}
|
||||
if ($item->path && str_starts_with($item->path, "/single/file/")) {
|
||||
$array[$item->path] = $item->path;
|
||||
|
||||
4
resources/assets/js/store/actions.js
vendored
4
resources/assets/js/store/actions.js
vendored
@ -2786,7 +2786,7 @@ export default {
|
||||
break
|
||||
|
||||
default:
|
||||
msgId && dispatch("websocketSend", {type: 'receipt', msgId});
|
||||
msgId && dispatch("websocketSend", {type: 'receipt', msgId}).catch(_ => {});
|
||||
state.wsMsg = msgDetail;
|
||||
Object.values(state.wsListener).forEach((call) => {
|
||||
if (typeof call === "function") {
|
||||
@ -3055,7 +3055,7 @@ export default {
|
||||
state.wsPathValue = path;
|
||||
state.wsPathTimeout = setTimeout(() => {
|
||||
if (state.wsPathValue == path) {
|
||||
dispatch("websocketSend", {type: 'path', data: {path}});
|
||||
dispatch("websocketSend", {type: 'path', data: {path}}).catch(_ => {});
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -64,6 +64,7 @@ export default {
|
||||
wsListener: {},
|
||||
wsReadTimeout: null,
|
||||
wsReadWaitData: {},
|
||||
wsCallReconnect: 0,
|
||||
|
||||
// 会员信息
|
||||
userInfo: {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user