removed cache for existence of player
This commit is contained in:
parent
b816eb1c06
commit
1170a528d6
|
|
@ -365,7 +365,6 @@ class AdminController extends Controller
|
||||||
$cache = Option::form('cache', OptionForm::AUTO_DETECT, function ($form) {
|
$cache = Option::form('cache', OptionForm::AUTO_DETECT, function ($form) {
|
||||||
$form->checkbox('enable_avatar_cache')->label();
|
$form->checkbox('enable_avatar_cache')->label();
|
||||||
$form->checkbox('enable_preview_cache')->label();
|
$form->checkbox('enable_preview_cache')->label();
|
||||||
$form->checkbox('enable_notfound_cache', '404')->label();
|
|
||||||
})
|
})
|
||||||
->type('warning')
|
->type('warning')
|
||||||
->addButton([
|
->addButton([
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Listeners;
|
|
||||||
|
|
||||||
use App\Events;
|
|
||||||
use App\Models\Player;
|
|
||||||
use Cache;
|
|
||||||
use Illuminate\Events\Dispatcher;
|
|
||||||
|
|
||||||
class CachePlayerExists
|
|
||||||
{
|
|
||||||
public function subscribe(Dispatcher $events)
|
|
||||||
{
|
|
||||||
$events->listen(Events\CheckPlayerExists::class, [$this, 'remember']);
|
|
||||||
$events->listen(Events\PlayerWasAdded::class, [$this, 'forget']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function remember($event)
|
|
||||||
{
|
|
||||||
$key = "notfound-{$event->playerName}";
|
|
||||||
|
|
||||||
if ($event->playerName && is_null(Cache::get($key))) {
|
|
||||||
$player = Player::where('name', $event->playerName)->first();
|
|
||||||
|
|
||||||
if (!$player) {
|
|
||||||
Cache::forever($key, '1');
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function forget($event)
|
|
||||||
{
|
|
||||||
Cache::forget("notfound-{$event->player->name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Events;
|
|
||||||
use App\Listeners;
|
|
||||||
use Event;
|
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
class EventServiceProvider extends ServiceProvider
|
class EventServiceProvider extends ServiceProvider
|
||||||
|
|
@ -36,18 +33,4 @@ class EventServiceProvider extends ServiceProvider
|
||||||
'App\Listeners\SerializeGlobals',
|
'App\Listeners\SerializeGlobals',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Register any other events for your application.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
if (option('enable_notfound_cache')) {
|
|
||||||
Event::subscribe(Listeners\CachePlayerExists::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,5 +206,3 @@ cache:
|
||||||
enable_preview_cache:
|
enable_preview_cache:
|
||||||
title: Texture Preivew
|
title: Texture Preivew
|
||||||
label: Enable caching texture preivew
|
label: Enable caching texture preivew
|
||||||
enable_notfound_cache:
|
|
||||||
label: Enable caching whether player is existed or not
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@
|
||||||
- Removed Universal Skin API from core. (Install plugin if you need it.)
|
- Removed Universal Skin API from core. (Install plugin if you need it.)
|
||||||
- Removed auto update check.
|
- Removed auto update check.
|
||||||
- Removed cache for Profile JSON.
|
- Removed cache for Profile JSON.
|
||||||
|
- Removed cache for existence of player.
|
||||||
|
|
||||||
## Internal Changes
|
## Internal Changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@
|
||||||
- 移除 Universal Skin API(如有需要,请安装插件)
|
- 移除 Universal Skin API(如有需要,请安装插件)
|
||||||
- 移除自动更新检查
|
- 移除自动更新检查
|
||||||
- 移除对 Profile JSON 的缓存
|
- 移除对 Profile JSON 的缓存
|
||||||
|
- 移除对角色存在与否的缓存
|
||||||
|
|
||||||
## 内部更改
|
## 内部更改
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,11 +190,9 @@ class AdminFormsTest extends BrowserKitTestCase
|
||||||
->see(trans('options.cache.driver', ['driver' => config('cache.default')]))
|
->see(trans('options.cache.driver', ['driver' => config('cache.default')]))
|
||||||
->check('enable_avatar_cache')
|
->check('enable_avatar_cache')
|
||||||
->check('enable_preview_cache')
|
->check('enable_preview_cache')
|
||||||
->check('enable_notfound_cache')
|
|
||||||
->press('submit_cache');
|
->press('submit_cache');
|
||||||
$this->assertTrue(option('enable_avatar_cache'));
|
$this->assertTrue(option('enable_avatar_cache'));
|
||||||
$this->assertTrue(option('enable_preview_cache'));
|
$this->assertTrue(option('enable_preview_cache'));
|
||||||
$this->assertTrue(option('enable_notfound_cache'));
|
|
||||||
|
|
||||||
Cache::shouldReceive('flush');
|
Cache::shouldReceive('flush');
|
||||||
$this->visit('/admin/resource')
|
$this->visit('/admin/resource')
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests;
|
|
||||||
|
|
||||||
use App\Events;
|
|
||||||
use App\Models\Player;
|
|
||||||
use Cache;
|
|
||||||
use Event;
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
|
|
||||||
class CachePlayerExistsTest extends TestCase
|
|
||||||
{
|
|
||||||
use DatabaseTransactions;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
option(['enable_notfound_cache' => true]);
|
|
||||||
$provider = new \App\Providers\EventServiceProvider(app());
|
|
||||||
$provider->boot();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRemember()
|
|
||||||
{
|
|
||||||
$player = factory(Player::class)->create();
|
|
||||||
Cache::shouldReceive('get')
|
|
||||||
->times(2)
|
|
||||||
->andReturn(null)
|
|
||||||
->andReturn(null);
|
|
||||||
Cache::shouldReceive('forever')->once()->with('notfound-nope', '1');
|
|
||||||
|
|
||||||
event(new Events\CheckPlayerExists(null));
|
|
||||||
event(new Events\CheckPlayerExists($player->name));
|
|
||||||
event(new Events\CheckPlayerExists('nope'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testForget()
|
|
||||||
{
|
|
||||||
$player = factory(Player::class)->create();
|
|
||||||
event(new Events\PlayerWasAdded($player));
|
|
||||||
Cache::shouldReceive('forget')->with("notfound-{$player->name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user