mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-24 03:59:08 -05:00
(Update) Optimize Many Queries
- reduce load
This commit is contained in:
@@ -21,18 +21,18 @@ class ActivationController extends Controller
|
||||
{
|
||||
public function activate($token)
|
||||
{
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
|
||||
$activation = UserActivation::with('user')->where('token', $token)->firstOrFail();
|
||||
if ($activation->user->id && $activation->user->group->id != $bannedGroup->id) {
|
||||
if ($activation->user->id && $activation->user->group->id != $bannedGroup) {
|
||||
$activation->user->active = 1;
|
||||
$activation->user->can_upload = 1;
|
||||
$activation->user->can_download = 1;
|
||||
$activation->user->can_request = 1;
|
||||
$activation->user->can_comment = 1;
|
||||
$activation->user->can_invite = 1;
|
||||
$activation->user->group_id = $memberGroup->id;
|
||||
$activation->user->group_id = $memberGroup;
|
||||
$activation->user->save();
|
||||
|
||||
// Activity Log
|
||||
|
||||
@@ -66,27 +66,27 @@ class LoginController extends Controller
|
||||
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
|
||||
if ($user->active == 0 || $user->group_id == $validatingGroup->id) {
|
||||
if ($user->active == 0 || $user->group_id == $validatingGroup) {
|
||||
auth()->logout();
|
||||
$request->session()->flush();
|
||||
return redirect()->route('login')
|
||||
->with(Toastr::error('This account has not been activated and is still in validating group. Please check your email for activation link. If you did not receive the activation code, please click "forgot password" and complete the steps.', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
if ($user->group_id == $bannedGroup->id) {
|
||||
if ($user->group_id == $bannedGroup) {
|
||||
auth()->logout();
|
||||
$request->session()->flush();
|
||||
return redirect()->route('login')
|
||||
->with(Toastr::error('This account is Banned!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
if ($user->group_id == $disabledGroup->id) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
if ($user->group_id == $disabledGroup) {
|
||||
$user->group_id = $memberGroup;
|
||||
$user->can_upload = 1;
|
||||
$user->can_download = 1;
|
||||
$user->can_comment = 1;
|
||||
@@ -99,8 +99,8 @@ class LoginController extends Controller
|
||||
->with(Toastr::info('Welcome Back! Your Account Is No Longer Disabled!', $user->username, ['options']));
|
||||
}
|
||||
|
||||
if (auth()->viaRemember() && auth()->user()->group_id == $disabledGroup->id) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
if (auth()->viaRemember() && auth()->user()->group_id == $disabledGroup) {
|
||||
$user->group_id = $memberGroup;
|
||||
$user->can_upload = 1;
|
||||
$user->can_download = 1;
|
||||
$user->can_comment = 1;
|
||||
|
||||
@@ -67,7 +67,7 @@ class RegisterController extends Controller
|
||||
->with(Toastr::error('Invalid or Expired Invite Key!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$user = new User();
|
||||
$user->username = $request->input('username');
|
||||
$user->email = $request->input('email');
|
||||
@@ -77,7 +77,7 @@ class RegisterController extends Controller
|
||||
$user->uploaded = config('other.default_upload');
|
||||
$user->downloaded = config('other.default_download');
|
||||
$user->style = config('other.default_style', 0);
|
||||
$user->group_id = $validatingGroup->id;
|
||||
$user->group_id = $validatingGroup;
|
||||
|
||||
if (config('email-white-blacklist.enabled') === 'allow' && config('captcha.enabled') == true) {
|
||||
$v = validator($request->all(), [
|
||||
|
||||
@@ -20,13 +20,13 @@ class ResetPasswordController extends Controller
|
||||
|
||||
protected function resetPassword($user, $password)
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
$user->password = bcrypt($password);
|
||||
$user->remember_token = Str::random(60);
|
||||
|
||||
if ($user->group_id === $validatingGroup->id) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
if ($user->group_id === $validatingGroup) {
|
||||
$user->group_id = $memberGroup;
|
||||
}
|
||||
|
||||
$user->active = true;
|
||||
|
||||
@@ -84,11 +84,11 @@ class ForumController extends Controller
|
||||
$categories = Forum::oldest('position')->get();
|
||||
|
||||
// Total Forums Count
|
||||
$num_forums = Forum::all()->count();
|
||||
$num_forums = Forum::count();
|
||||
// Total Posts Count
|
||||
$num_posts = Post::all()->count();
|
||||
$num_posts = Post::count();
|
||||
// Total Topics Count
|
||||
$num_topics = Topic::all()->count();
|
||||
$num_topics = Topic::count();
|
||||
|
||||
return view('forum.index', [
|
||||
'categories' => $categories,
|
||||
|
||||
@@ -48,13 +48,13 @@ class BanController extends Controller
|
||||
{
|
||||
$user = User::findOrFail($id);
|
||||
$staff = auth()->user();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
|
||||
if ($user->group->is_modo || auth()->user()->id == $user->id) {
|
||||
return redirect()->route('profile', ['username' => $user->username, 'id' => $user->id])
|
||||
->with(Toastr::error('You Cannot Ban Yourself Or Other Staff!', 'Whoops!', ['options']));
|
||||
} else {
|
||||
$user->group_id = $bannedGroup->id;
|
||||
$user->group_id = $bannedGroup;
|
||||
$user->can_upload = 0;
|
||||
$user->can_download = 0;
|
||||
$user->can_comment = 0;
|
||||
|
||||
@@ -18,6 +18,7 @@ use App\Peer;
|
||||
use App\User;
|
||||
use App\Client;
|
||||
use App\Report;
|
||||
use App\Group;
|
||||
use App\Helpers\SystemInformation;
|
||||
use Spatie\SslCertificate\SslCertificate;
|
||||
|
||||
@@ -31,30 +32,30 @@ class HomeController extends Controller
|
||||
public function home()
|
||||
{
|
||||
// User Info
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
|
||||
$num_user = User::all()->count();
|
||||
$banned = User::where('group_id', $bannedGroup->id)->count();
|
||||
$validating = User::where('group_id', $validatingGroup->id)->count();
|
||||
$num_user = User::count();
|
||||
$banned = User::where('group_id', $bannedGroup)->count();
|
||||
$validating = User::where('group_id', $validatingGroup)->count();
|
||||
|
||||
// Torrent Info
|
||||
$num_torrent = Torrent::all()->count();
|
||||
$num_torrent = Torrent::count();
|
||||
$pending = Torrent::pending()->count();
|
||||
$rejected = Torrent::rejected()->count();
|
||||
|
||||
// Peers Info
|
||||
$peers = Peer::all()->count();
|
||||
$peers = Peer::count();
|
||||
$seeders = Peer::where('seeder', 1)->count();
|
||||
$leechers = Peer::where('seeder', 0)->count();
|
||||
|
||||
// Seedbox Info
|
||||
$seedboxes = Client::all()->count();
|
||||
$highspeed_users = Client::all()->count();
|
||||
$seedboxes = Client::count();
|
||||
$highspeed_users = Client::count();
|
||||
$highspeed_torrents = Torrent::where('highspeed', 1)->count();
|
||||
|
||||
// User Info
|
||||
$reports = Report::all()->count();
|
||||
$reports = Report::count();
|
||||
$unsolved = Report::where('solved', 0)->count();
|
||||
$solved = Report::where('solved', 1)->count();
|
||||
|
||||
|
||||
@@ -278,12 +278,12 @@ class UserController extends Controller
|
||||
*/
|
||||
public function massValidateUsers()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->first();
|
||||
$users = User::where('active', '=', 0)->where('group_id', '=', $validatingGroup->id)->get();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
$users = User::where('active', '=', 0)->where('group_id', '=', $validatingGroup)->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
$user->group_id = $memberGroup;
|
||||
$user->active = 1;
|
||||
$user->can_upload = 1;
|
||||
$user->can_download = 1;
|
||||
|
||||
@@ -47,25 +47,25 @@ class StatsController extends Controller
|
||||
|
||||
// Total Disabled Members Count
|
||||
$disabled_user = cache()->remember('disabled_user', 60, function () {
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->first();
|
||||
return User::where('group_id', '=', $disabledGroup->id)->count();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
return User::where('group_id', '=', $disabledGroup)->count();
|
||||
});
|
||||
|
||||
// Total Pruned Members Count
|
||||
$pruned_user = cache()->remember('pruned_user', 60, function () {
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->first();
|
||||
return User::onlyTrashed()->where('group_id', '=', $prunedGroup->id)->count();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
return User::onlyTrashed()->where('group_id', '=', $prunedGroup)->count();
|
||||
});
|
||||
|
||||
// Total Banned Members Count
|
||||
$banned_user = cache()->remember('banned_user', 60, function () {
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
return User::where('group_id', '=', $bannedGroup->id)->count();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
return User::where('group_id', '=', $bannedGroup)->count();
|
||||
});
|
||||
|
||||
// Total Torrents Count
|
||||
$num_torrent = cache()->remember('num_torrent', 60, function () {
|
||||
return Torrent::all()->count();
|
||||
return Torrent::count();
|
||||
});
|
||||
|
||||
// Total Categories With Torrent Count
|
||||
@@ -93,7 +93,7 @@ class StatsController extends Controller
|
||||
|
||||
// Total Peers
|
||||
$num_peers = cache()->remember('num_peers', 60, function () {
|
||||
return Peer::all()->count();
|
||||
return Peer::count();
|
||||
});
|
||||
|
||||
//Total Upload Traffic Without Double Upload
|
||||
@@ -151,10 +151,10 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function uploaded()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
|
||||
// Fetch Top Uploaders
|
||||
$uploaded = User::latest('uploaded')->whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->take(100)->get();
|
||||
@@ -169,10 +169,10 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function downloaded()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
|
||||
// Fetch Top Downloaders
|
||||
$downloaded = User::latest('downloaded')->whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->take(100)->get();
|
||||
@@ -226,10 +226,10 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function bankers()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
|
||||
// Fetch Top Bankers
|
||||
$bankers = User::latest('seedbonus')->whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->take(100)->get();
|
||||
|
||||
@@ -28,7 +28,7 @@ class CheckIfActive
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
|
||||
if ($user && $user->group_id == $validatingGroup || $user->active == 0) {
|
||||
auth()->logout();
|
||||
|
||||
@@ -28,7 +28,7 @@ class CheckIfBanned
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
|
||||
if ($user && $user->group_id == $bannedGroup) {
|
||||
auth()->logout();
|
||||
|
||||
Reference in New Issue
Block a user