remove unnecessary SQL queries

This commit is contained in:
Pig Fang 2020-06-11 15:34:18 +08:00
parent 6c4eb5441e
commit d018f207f3
6 changed files with 4 additions and 46 deletions

View File

@ -75,6 +75,7 @@ class UserController extends Controller
public function scoreInfo()
{
/** @var User */
$user = Auth::user();
return response()->json([
@ -87,7 +88,7 @@ class UserController extends Controller
'players' => (int) option('score_per_player'),
],
'usage' => [
'players' => $user->players->count(),
'players' => $user->players()->count(),
'storage' => (int) Texture::where('uploader', $user->uid)->sum('size'),
],
'signAfterZero' => (bool) option('sign_after_zero'),

View File

@ -1,19 +0,0 @@
<?php
namespace App\Listeners;
class ResetInvalidTextureForPlayer
{
public function handle($event)
{
$player = $event->player;
foreach (['skin', 'cape'] as $type) {
$field = "tid_$type";
if (!\App\Models\Texture::find($player->$field)) {
$player->$field = 0;
}
}
$player->save();
}
}

View File

@ -9,9 +9,6 @@ class EventServiceProvider extends ServiceProvider
{
// The event listener mappings for the application.
protected $listen = [
'App\Events\PlayerRetrieved' => [
Listeners\ResetInvalidTextureForPlayer::class,
],
'App\Events\PluginWasEnabled' => [
Listeners\CopyPluginAssets::class,
Listeners\GeneratePluginTranslations::class,

View File

@ -51,6 +51,7 @@
- Changed icon of "Walking/Running" button of skin viewer.
- Changed API of retrieving all players.
- Changed format of avatar and 2D preview to WebP.
- Reduced some unnecessary SQL queries.
## Fixed

View File

@ -51,6 +51,7 @@
- 更换皮肤预览器的「行走/奔跑」按钮图标
- 更改获取角色的 API
- 头像和预览图的格式改为 WebP
- 减少不必要的 SQL 查询语句
## 修复

View File

@ -1,23 +0,0 @@
<?php
namespace Tests;
use App\Models\Player;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ResetInvalidTextureForPlayerTest extends TestCase
{
use DatabaseTransactions;
public function testHandle()
{
$pid = factory(Player::class)->create([
'tid_skin' => 1,
'tid_cape' => 2,
])->pid;
$player = Player::find($pid);
$this->assertEquals(0, $player->tid_skin);
$this->assertEquals(0, $player->tid_cape);
}
}