perf: 删除冗余字段

This commit is contained in:
kuaifan 2024-11-02 10:01:42 +08:00
parent ebe953cf63
commit 87e46ec5a5
6 changed files with 36 additions and 10 deletions

View File

@ -200,7 +200,6 @@ class WebSocketDialogMsg extends AbstractModel
'msg_id' => $this->id, 'msg_id' => $this->id,
'userid' => $userid, 'userid' => $userid,
'after' => 1, 'after' => 1,
'live' => 1,
]); ]);
if ($msgRead->saveOrIgnore()) { if ($msgRead->saveOrIgnore()) {
$this->send = WebSocketDialogMsgRead::whereMsgId($this->id)->count(); $this->send = WebSocketDialogMsgRead::whereMsgId($this->id)->count();

View File

@ -16,7 +16,6 @@ use Carbon\Carbon;
* @property int|null $email 是否发了邮件 * @property int|null $email 是否发了邮件
* @property int|null $after 在阅读之后才添加的记录 * @property int|null $after 在阅读之后才添加的记录
* @property int|null $dot 红点标记 * @property int|null $dot 红点标记
* @property int|null $live 是否在会话里
* @property \Illuminate\Support\Carbon|null $read_at 阅读时间 * @property \Illuminate\Support\Carbon|null $read_at 阅读时间
* @property-read \App\Models\WebSocketDialogMsg|null $webSocketDialogMsg * @property-read \App\Models\WebSocketDialogMsg|null $webSocketDialogMsg
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend() * @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend()
@ -33,7 +32,6 @@ use Carbon\Carbon;
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereDot($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereDot($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereEmail($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereLive($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereMention($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereMention($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereMsgId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereMsgId($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereReadAt($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsgRead whereReadAt($value)

View File

@ -4,7 +4,6 @@ namespace App\Observers;
use App\Models\Deleted; use App\Models\Deleted;
use App\Models\WebSocketDialog; use App\Models\WebSocketDialog;
use App\Models\WebSocketDialogMsgRead;
use App\Models\WebSocketDialogUser; use App\Models\WebSocketDialogUser;
class WebSocketDialogObserver class WebSocketDialogObserver
@ -40,7 +39,6 @@ class WebSocketDialogObserver
public function deleted(WebSocketDialog $webSocketDialog) public function deleted(WebSocketDialog $webSocketDialog)
{ {
Deleted::record('dialog', $webSocketDialog->id, $this->userids($webSocketDialog)); Deleted::record('dialog', $webSocketDialog->id, $this->userids($webSocketDialog));
WebSocketDialogMsgRead::whereDialogId($webSocketDialog->id)->update(['live' => 0]);
} }
/** /**
@ -53,7 +51,6 @@ class WebSocketDialogObserver
{ {
$userids = $this->userids($webSocketDialog); $userids = $this->userids($webSocketDialog);
Deleted::forget('dialog', $webSocketDialog->id, $userids); Deleted::forget('dialog', $webSocketDialog->id, $userids);
WebSocketDialogMsgRead::whereDialogId($webSocketDialog->id)->whereIn('userid', $userids)->update(['live' => 1]);
} }
/** /**

View File

@ -3,7 +3,6 @@
namespace App\Observers; namespace App\Observers;
use App\Models\Deleted; use App\Models\Deleted;
use App\Models\WebSocketDialogMsgRead;
use App\Models\WebSocketDialogUser; use App\Models\WebSocketDialogUser;
use Carbon\Carbon; use Carbon\Carbon;
@ -30,7 +29,6 @@ class WebSocketDialogUserObserver
} }
} }
Deleted::forget('dialog', $webSocketDialogUser->dialog_id, $webSocketDialogUser->userid); Deleted::forget('dialog', $webSocketDialogUser->dialog_id, $webSocketDialogUser->userid);
WebSocketDialogMsgRead::whereDialogId($webSocketDialogUser->dialog_id)->whereUserid($webSocketDialogUser->userid)->update(['live' => 1]);
} }
/** /**
@ -53,7 +51,6 @@ class WebSocketDialogUserObserver
public function deleted(WebSocketDialogUser $webSocketDialogUser) public function deleted(WebSocketDialogUser $webSocketDialogUser)
{ {
Deleted::record('dialog', $webSocketDialogUser->dialog_id, $webSocketDialogUser->userid); Deleted::record('dialog', $webSocketDialogUser->dialog_id, $webSocketDialogUser->userid);
WebSocketDialogMsgRead::whereDialogId($webSocketDialogUser->dialog_id)->whereUserid($webSocketDialogUser->userid)->update(['live' => 0]);
} }
/** /**

View File

@ -128,7 +128,6 @@ class WebSocketDialogMsgTask extends AbstractTask
'mention' => $mention, 'mention' => $mention,
'silence' => $silence, 'silence' => $silence,
'dot' => $dot, 'dot' => $dot,
'live' => 1,
])->saveOrIgnore(); ])->saveOrIgnore();
$array[$userid] = [ $array[$userid] = [
'userid' => $userid, 'userid' => $userid,

View File

@ -0,0 +1,36 @@
<?php
use App\Models\WebSocketDialog;
use App\Models\WebSocketDialogMsg;
use App\Models\WebSocketDialogMsgRead;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RemoveWebSocketDialogMsgReadsLive extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('web_socket_dialog_msg_reads', function (Blueprint $table) use (&$isAdd) {
if (Schema::hasColumn('web_socket_dialog_msg_reads', 'live')) {
$table->dropIndex(['userid', 'live', 'msg_id']);
$table->dropColumn('live');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}