update: optimization stat user

This commit is contained in:
tokumeikoi 2022-03-29 14:57:09 +08:00
parent 20b60d553c
commit af2f6a31da
4 changed files with 16 additions and 9 deletions

View File

@ -52,7 +52,7 @@ class StatUserJob implements ShouldQueue
} }
$data = StatUser::where('record_at', $recordAt) $data = StatUser::where('record_at', $recordAt)
->where('server_id', $this->server->id) ->where('server_rate', $this->server->rate)
->where('user_id', $this->userId) ->where('user_id', $this->userId)
->first(); ->first();
if ($data) { if ($data) {
@ -67,8 +67,6 @@ class StatUserJob implements ShouldQueue
} else { } else {
if (!StatUser::create([ if (!StatUser::create([
'user_id' => $this->userId, 'user_id' => $this->userId,
'server_id' => $this->server->id,
'server_type' => $this->protocol,
'server_rate' => $this->server->rate, 'server_rate' => $this->server->rate,
'u' => $this->u, 'u' => $this->u,
'd' => $this->d, 'd' => $this->d,

View File

@ -297,8 +297,6 @@ DROP TABLE IF EXISTS `v2_stat_user`;
CREATE TABLE `v2_stat_user` ( CREATE TABLE `v2_stat_user` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL, `user_id` int(11) NOT NULL,
`server_id` int(11) NOT NULL,
`server_type` char(11) NOT NULL,
`server_rate` decimal(10,2) NOT NULL, `server_rate` decimal(10,2) NOT NULL,
`u` bigint(20) NOT NULL, `u` bigint(20) NOT NULL,
`d` bigint(20) NOT NULL, `d` bigint(20) NOT NULL,
@ -307,9 +305,10 @@ CREATE TABLE `v2_stat_user` (
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `server_id` (`server_id`), UNIQUE KEY `server_rate_user_id_record_at` (`server_rate`,`user_id`,`record_at`),
KEY `user_id` (`user_id`), KEY `user_id` (`user_id`),
KEY `record_at` (`record_at`) KEY `record_at` (`record_at`),
KEY `server_rate` (`server_rate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@ -377,4 +376,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2022-03-17 05:35:39 -- 2022-03-29 06:56:01

View File

@ -524,3 +524,13 @@ ADD `handling_fee_percent` decimal(5,2) NULL AFTER `handling_fee_fixed`;
ALTER TABLE `v2_order` ALTER TABLE `v2_order`
ADD `handling_amount` int(11) NULL AFTER `total_amount`; ADD `handling_amount` int(11) NULL AFTER `total_amount`;
ALTER TABLE `v2_stat_user`
ADD UNIQUE `server_rate_user_id_record_at` (`server_rate`, `user_id`, `record_at`),
ADD INDEX `server_rate` (`server_rate`),
DROP INDEX `server_id_user_id_record_at`,
DROP INDEX `server_id`;
ALTER TABLE `v2_stat_user`
DROP `server_id`,
DROP `server_type`;

File diff suppressed because one or more lines are too long