fix: sqlite stats queue and admin login redirect
Some checks are pending
Docker Build and Publish / build (push) Waiting to run

This commit is contained in:
xboard 2025-01-09 21:15:57 +08:00
parent ed43ffc3f5
commit 70998d0c08
3 changed files with 42 additions and 24 deletions

View File

@ -52,21 +52,28 @@ class StatServerJob implements ShouldQueue
$u += $traffic[0];
$d += $traffic[1];
}
// Update or create traffic stats
DB::transaction(function () use ($u, $d, $recordAt) {
StatServer::updateOrCreate(
[
$stat = StatServer::lockForUpdate()
->where('record_at', $recordAt)
->where('server_id', $this->server['id'])
->where('server_type', $this->protocol)
->where('record_type', $this->recordType)
->first();
if ($stat) {
$stat->u += $u;
$stat->d += $d;
$stat->save();
} else {
StatServer::create([
'record_at' => $recordAt,
'server_id' => $this->server['id'],
'server_type' => $this->protocol,
'record_type' => $this->recordType,
],
[
'u' => DB::raw("COALESCE(u, 0) + $u"),
'd' => DB::raw("COALESCE(d, 0) + $d"),
]
);
'u' => $u,
'd' => $d,
]);
}
});
}
}

View File

@ -47,19 +47,30 @@ class StatUserJob implements ShouldQueue
: strtotime(date('Y-m-d'));
foreach ($this->data as $uid => $v) {
StatUser::updateOrCreate(
[
'user_id' => $uid,
'server_rate' => $this->server['rate'],
'record_at' => $recordAt,
'record_type' => $this->recordType,
],
[
'u' => DB::raw('COALESCE(u, 0) + ' . ($v[0] * $this->server['rate'])),
'd' => DB::raw('COALESCE(d, 0) + ' . ($v[1] * $this->server['rate'])),
't' => time(),
]
);
DB::transaction(function () use ($uid, $v, $recordAt) {
$stat = StatUser::lockForUpdate()
->where('user_id', $uid)
->where('server_rate', $this->server['rate'])
->where('record_at', $recordAt)
->where('record_type', $this->recordType)
->first();
if ($stat) {
$stat->u += ($v[0] * $this->server['rate']);
$stat->d += ($v[1] * $this->server['rate']);
$stat->t = time();
$stat->save();
} else {
StatUser::create([
'user_id' => $uid,
'server_rate' => $this->server['rate'],
'record_at' => $recordAt,
'record_type' => $this->recordType,
'u' => ($v[0] * $this->server['rate']),
'd' => ($v[1] * $this->server['rate']),
't' => time(),
]);
}
});
}
}
}

File diff suppressed because one or more lines are too long