From a0f6a17005f8fb8d557ec0205424f8fa3a905b8b Mon Sep 17 00:00:00 2001 From: Pang Date: Sun, 24 Dec 2023 10:46:50 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/WebSocketDialog.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 8dbcbcd2a..a02478ae0 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -192,10 +192,26 @@ class WebSocketDialog extends AbstractModel if ($hasData === true) { $msgBuilder = WebSocketDialogMsg::whereDialogId($this->id); $this->has_tag = $msgBuilder->clone()->where('tag', '>', 0)->exists(); + $this->has_todo = $msgBuilder->clone()->where('todo', '>', 0)->exists(); $this->has_image = $msgBuilder->clone()->whereMtype('image')->exists(); $this->has_file = $msgBuilder->clone()->whereMtype('file')->exists(); $this->has_link = $msgBuilder->clone()->whereLink(1)->exists(); - $this->has_todo = $msgBuilder->clone()->where('todo', '>', 0)->exists(); + Cache::forever("Dialog::tag:" . $this->id, Base::array2json([ + 'has_tag' => $this->has_tag, + 'has_todo' => $this->has_todo, + 'has_image' => $this->has_image, + 'has_file' => $this->has_file, + 'has_link' => $this->has_link, + ])); + } else { + $tagData = Base::json2array(Cache::get("Dialog::tag:" . $this->id)); + if ($tagData) { + $this->has_tag = !!$tagData['has_tag']; + $this->has_todo = !!$tagData['has_todo']; + $this->has_image = !!$tagData['has_image']; + $this->has_file = !!$tagData['has_file']; + $this->has_link = !!$tagData['has_link']; + } } return $this; }