(Update) Cache Queries

This commit is contained in:
HDVinnie
2020-02-10 09:46:05 -05:00
parent 4a0d127502
commit ea58e49ad2
+3 -14
View File
@@ -123,11 +123,7 @@ class AnnounceController extends Controller
}
// Check Passkey Against Cache or Users Table
if (Cache::has("user.{$passkey}")) {
$user = Cache::get("user.{$passkey}");
} else {
$user = User::where('passkey', '=', $passkey)->first();
}
$user = Cache::get("user.{$passkey}") ?? User::where('passkey', '=', $passkey)->first();
// If Passkey Doesn't Exist Return Error to Client
if ($user === null) {
@@ -210,14 +206,7 @@ class AnnounceController extends Controller
}
// Check Info Hash Against Cache or Torrents Table
if (Cache::has("torrent.{$info_hash}")) {
$torrent = Cache::get("torrent.{$info_hash}");
} else {
$torrent = Torrent::select(['id', 'status', 'free', 'doubleup', 'times_completed', 'seeders', 'leechers'])
->withAnyStatus()
->where('info_hash', '=', $info_hash)
->first();
}
$torrent = Cache::get("torrent.{$info_hash}") ?? Torrent::select(['id', 'status', 'free', 'doubleup', 'times_completed', 'seeders', 'leechers'])->withAnyStatus()->where('info_hash', '=', $info_hash)->first();
// If Torrent Doesnt Exsist Return Error to Client
if ($torrent === null) {
@@ -248,7 +237,7 @@ class AnnounceController extends Controller
// Pull Count On Users Peers Per Torrent For Rate Limiting
$connections = Cache::remember("user_connections.{$torrent->id}", 1800, function () use ($torrent, $user) {
return Peer::where('torrent_id', '=', $torrent->id)->where('user_id', '=', $user->id)->count();
return Peer::where('torrent_id', '=', $torrent->id)->where('user_id', '=', $user->id)->count();
});
// If Users Peer Count On A Single Torrent Is Greater Than X Return Error to Client