mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 04:32:49 +00:00
perf: 群聊总人数排除机器人
This commit is contained in:
parent
5f87067a75
commit
be9a968ad9
@ -210,8 +210,8 @@ class AbstractModel extends Model
|
|||||||
/**
|
/**
|
||||||
* 数据库更新或插入
|
* 数据库更新或插入
|
||||||
* @param $where
|
* @param $where
|
||||||
* @param array $update 存在时更新的内容
|
* @param array|\Closure $update 存在时更新的内容
|
||||||
* @param array $insert 不存在时插入的内容,如果没有则插入更新内容
|
* @param array|\Closure $insert 不存在时插入的内容,如果没有则插入更新内容
|
||||||
* @param bool $isInsert 是否是插入数据
|
* @param bool $isInsert 是否是插入数据
|
||||||
* @return AbstractModel|\Illuminate\Database\Eloquent\Builder|Model|object|static|null
|
* @return AbstractModel|\Illuminate\Database\Eloquent\Builder|Model|object|static|null
|
||||||
*/
|
*/
|
||||||
@ -220,6 +220,12 @@ class AbstractModel extends Model
|
|||||||
$row = static::where($where)->first();
|
$row = static::where($where)->first();
|
||||||
if (empty($row)) {
|
if (empty($row)) {
|
||||||
$row = new static;
|
$row = new static;
|
||||||
|
if ($update instanceof \Closure) {
|
||||||
|
$update = $update();
|
||||||
|
}
|
||||||
|
if ($insert instanceof \Closure) {
|
||||||
|
$insert = $insert();
|
||||||
|
}
|
||||||
$array = array_merge($where, $insert ?: $update);
|
$array = array_merge($where, $insert ?: $update);
|
||||||
if (isset($array[$row->primaryKey])) {
|
if (isset($array[$row->primaryKey])) {
|
||||||
unset($array[$row->primaryKey]);
|
unset($array[$row->primaryKey]);
|
||||||
@ -227,6 +233,9 @@ class AbstractModel extends Model
|
|||||||
$row->updateInstance($array);
|
$row->updateInstance($array);
|
||||||
$isInsert = true;
|
$isInsert = true;
|
||||||
} elseif ($update) {
|
} elseif ($update) {
|
||||||
|
if ($update instanceof \Closure) {
|
||||||
|
$update = $update();
|
||||||
|
}
|
||||||
$row->updateInstance($update);
|
$row->updateInstance($update);
|
||||||
$isInsert = false;
|
$isInsert = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -219,7 +219,11 @@ class Project extends AbstractModel
|
|||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
], [
|
], [
|
||||||
'important' => 1
|
'important' => 1
|
||||||
]);
|
], function () use ($userid) {
|
||||||
|
return [
|
||||||
|
'bot' => User::isBot($userid) ? 1 : 0,
|
||||||
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
WebSocketDialogUser::whereDialogId($this->dialog_id)->whereNotIn('userid', $userids)->whereImportant(1)->remove();
|
WebSocketDialogUser::whereDialogId($this->dialog_id)->whereNotIn('userid', $userids)->whereImportant(1)->remove();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1180,7 +1180,11 @@ class ProjectTask extends AbstractModel
|
|||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
], [
|
], [
|
||||||
'important' => 1
|
'important' => 1
|
||||||
]);
|
], function () use ($userid) {
|
||||||
|
return [
|
||||||
|
'bot' => User::isBot($userid) ? 1 : 0,
|
||||||
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
WebSocketDialogUser::whereDialogId($this->dialog_id)->whereNotIn('userid', $userids)->whereImportant(1)->remove();
|
WebSocketDialogUser::whereDialogId($this->dialog_id)->whereNotIn('userid', $userids)->whereImportant(1)->remove();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -423,7 +423,11 @@ class WebSocketDialog extends AbstractModel
|
|||||||
WebSocketDialogUser::updateInsert([
|
WebSocketDialogUser::updateInsert([
|
||||||
'dialog_id' => $this->id,
|
'dialog_id' => $this->id,
|
||||||
'userid' => $value,
|
'userid' => $value,
|
||||||
], $updateData, [], $isInsert);
|
], $updateData, function() use ($value) {
|
||||||
|
return [
|
||||||
|
'bot' => User::isBot($value) ? 1 : 0,
|
||||||
|
];
|
||||||
|
}, $isInsert);
|
||||||
if ($isInsert) {
|
if ($isInsert) {
|
||||||
WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [
|
WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [
|
||||||
'notice' => User::userid2nickname($value) . " 已加入群组"
|
'notice' => User::userid2nickname($value) . " 已加入群组"
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddBotToWebSocketDialogUsersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('web_socket_dialog_users', function (Blueprint $table) {
|
||||||
|
if (!Schema::hasColumn('web_socket_dialog_users', 'bot')) {
|
||||||
|
$table->tinyInteger('bot')->nullable()->default(0)->after('userid')->comment('是否机器人');
|
||||||
|
$table->index('bot');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取表前缀
|
||||||
|
$prefix = DB::getTablePrefix();
|
||||||
|
|
||||||
|
// 使用原生SQL更新数据
|
||||||
|
/** @noinspection SqlNoDataSourceInspection */
|
||||||
|
DB::statement("
|
||||||
|
UPDATE {$prefix}web_socket_dialog_users du
|
||||||
|
INNER JOIN {$prefix}users u ON u.userid = du.userid
|
||||||
|
SET du.bot = 1
|
||||||
|
WHERE u.bot = 1
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('web_socket_dialog_users', function (Blueprint $table) {
|
||||||
|
if (Schema::hasColumn('web_socket_dialog_users', 'bot')) {
|
||||||
|
$table->dropIndex('bot');
|
||||||
|
$table->dropColumn('bot');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user