Fixes caching to actually clear the cache for *all* users, rather than the logged in user by using cache tags.
This commit is contained in:
parent
5d59d364f8
commit
cd0a45a777
|
@ -12,6 +12,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
||||||
### Fixed
|
### Fixed
|
||||||
* Fixes potential bug with invalid CIDR notation (ex: `192.168.1.1/z`) when adding allocations that could cause over 4 million records to be created at once.
|
* Fixes potential bug with invalid CIDR notation (ex: `192.168.1.1/z`) when adding allocations that could cause over 4 million records to be created at once.
|
||||||
* `[pre.4]` — Fixes bug preventing server updates from occurring by the system due to undefined `Auth::user()` in the event listener.
|
* `[pre.4]` — Fixes bug preventing server updates from occurring by the system due to undefined `Auth::user()` in the event listener.
|
||||||
|
* `[pre.4]` — Fixes `Server::byUuid()` caching to actually clear the cache for *all* users, rather than the logged in user by using cache tags.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
* Ability to assign multiple allocations at once when creating a new server.
|
* Ability to assign multiple allocations at once when creating a new server.
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace Pterodactyl\Models;
|
||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use Cache;
|
use Cache;
|
||||||
|
use Carbon;
|
||||||
use Javascript;
|
use Javascript;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
@ -113,7 +114,7 @@ class Server extends Model
|
||||||
public static function byUuid($uuid)
|
public static function byUuid($uuid)
|
||||||
{
|
{
|
||||||
// Results are cached because we call this functions a few times on page load.
|
// Results are cached because we call this functions a few times on page load.
|
||||||
$result = Cache::remember('Server.byUuid.' . $uuid . Auth::user()->uuid, 60, function () use ($uuid) {
|
$result = Cache::tags(['Model:Server', 'Model:Server:byUuid:' . $uuid])->remember('Model:Server:byUuid:' . $uuid . Auth::user()->uuid, Carbon::now()->addMinutes(15), function () use ($uuid) {
|
||||||
$query = self::with('service', 'node')->where(function ($q) use ($uuid) {
|
$query = self::with('service', 'node')->where(function ($q) use ($uuid) {
|
||||||
$q->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
|
$q->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Observers;
|
namespace Pterodactyl\Observers;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Cache;
|
use Cache;
|
||||||
use Carbon;
|
use Carbon;
|
||||||
use Pterodactyl\Events;
|
use Pterodactyl\Events;
|
||||||
|
@ -141,11 +140,15 @@ class ServerObserver
|
||||||
*/
|
*/
|
||||||
public function updated(Server $server)
|
public function updated(Server $server)
|
||||||
{
|
{
|
||||||
// Clear Caches
|
/**
|
||||||
if (Auth::user()) {
|
* The cached byUuid model calls are tagged with Model:Server:byUuid:<uuid>
|
||||||
Cache::forget('Server.byUuid.' . $server->uuid . Auth::user()->uuid);
|
* so that they can be accessed regardless of if there is an Auth::user()
|
||||||
Cache::forget('Server.byUuid.' . $server->uuidShort . Auth::user()->uuid);
|
* defined or not.
|
||||||
}
|
*
|
||||||
|
* We can also delete all cached byUuid items using the Model:Server tag.
|
||||||
|
*/
|
||||||
|
Cache::tags('Model:Server:byUuid:' . $server->uuid)->flush();
|
||||||
|
Cache::tags('Model:Server:byUuid:' . $server->uuidShort)->flush();
|
||||||
|
|
||||||
event(new Events\Server\Updated($server));
|
event(new Events\Server\Updated($server));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue