Skip to content

Commit

Permalink
fix: memory exhaustion
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Oct 25, 2024
1 parent 4b2fc58 commit 8df492d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions app/Http/Controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,29 +655,24 @@ public function getLikesLeaderboard(Request $request) {
abort(404);
}

$query = Character::with('user.rank')->with('image.features')->with('rarity')->with('image.species')->myo(0)->where(function ($query) {
//only display characters whose users allow likes
$query = Character::myo(0)->where(function ($query) {
$query = $query->whereRelation('user.settings', 'allow_character_likes', 1);
});

$imageQuery = CharacterImage::images(Auth::check() ? Auth::user() : null)->with('features')->with('rarity')->with('species')->with('features');
$query->whereIn('id', $imageQuery->pluck('character_id')->toArray());
$randomcharacter = $query->visible()->get()->random(1)->first() ?? null;
$randomcharacter = $query->visible(Auth::user())->get()->random(1)->first() ?? null;

if ($request->get('id')) {
$query->where(function ($query) use ($request) {
$query->where('characters.id', $request->get('id'));
});
}

if ($request->get('owner')) {
$owner = User::find($request->get('owner'));
$query->where(function ($query) use ($owner) {
$query->where('user_id', $owner->id);
});
}

if (!Auth::check() || !Auth::user()->hasPower('manage_characters')) {
if (!Auth::user()->hasPower('manage_characters')) {
$query->visible();
}

Expand Down

0 comments on commit 8df492d

Please sign in to comment.