mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-05-04 17:30:27 -05:00
Merge pull request #2944 from Roardom/announce-prepared-statement
(Update) Use prepared statement instead of eager loading peers
This commit is contained in:
@@ -388,11 +388,6 @@ class AnnounceController extends Controller
|
||||
$torrentId = Redis::connection('cache')->command('HGET', [$cacheKey, hex2bin($infoHash)]);
|
||||
|
||||
$torrent = Torrent::withoutGlobalScope(ApprovedScope::class)
|
||||
->with([
|
||||
'peers' => fn ($query) => $query
|
||||
->select(['id', 'torrent_id', 'peer_id', 'user_id', 'left', 'seeder', 'port', 'updated_at'])
|
||||
->selectRaw('INET6_NTOA(ip) as ip')
|
||||
])
|
||||
->select(['id', 'free', 'doubleup', 'seeders', 'leechers', 'times_completed', 'status'])
|
||||
->when(
|
||||
$torrentId === null,
|
||||
@@ -426,6 +421,16 @@ class AnnounceController extends Controller
|
||||
new TrackerException(151, [':status' => 'POSTPONED In Moderation'])
|
||||
);
|
||||
|
||||
// Don't use eager loading so that we can make use of mysql prepared statement caching.
|
||||
// If we use eager loading, then laravel will use `where torrent_id in (123)` instead of `where torrent_id = ?`
|
||||
$torrent->setRelation(
|
||||
'peers',
|
||||
Peer::select(['id', 'torrent_id', 'peer_id', 'user_id', 'left', 'seeder', 'port', 'updated_at'])
|
||||
->selectRaw('INET6_NTOA(ip) as ip')
|
||||
->where('torrent_id', '=', $torrent->id)
|
||||
->get()
|
||||
);
|
||||
|
||||
return $torrent;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user