From 8feeadbf4eb63b5c154c5d31bf145bc8c4a9b535 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 22 Feb 2021 23:03:49 -0700 Subject: [PATCH 1/2] Update user admin, remove expensive db query and add search --- .../Controllers/Admin/AdminUserController.php | 21 ++++++++-- resources/views/admin/users/home.blade.php | 38 +++++++++++-------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Admin/AdminUserController.php b/app/Http/Controllers/Admin/AdminUserController.php index a5f19f4dc..fd16aaa28 100644 --- a/app/Http/Controllers/Admin/AdminUserController.php +++ b/app/Http/Controllers/Admin/AdminUserController.php @@ -16,14 +16,27 @@ trait AdminUserController { public function users(Request $request) { + $search = $request->has('a') && $request->query('a') == 'search' ? $request->query('q') : null; $col = $request->query('col') ?? 'id'; $dir = $request->query('dir') ?? 'desc'; - $users = User::select('id', 'username', 'status') - ->withCount('statuses') + $offset = $request->has('page') ? $request->input('page') : 1; + $pagination = [ + 'prev' => $offset && $offset > 1 ? $offset - 1 : null, + 'next' => $offset + 1, + 'query' => $search ? '&a=search&q=' . $search : null + ]; + $users = User::select('id', 'username', 'status', 'profile_id') ->orderBy($col, $dir) - ->simplePaginate(10); + ->when($search, function($q, $search) { + return $q->where('username', 'like', "%{$search}%"); + }) + ->when($offset > 1, function($q, $offset) { + return $q->offset(($offset * 10)); + }) + ->limit(10) + ->get(); - return view('admin.users.home', compact('users')); + return view('admin.users.home', compact('users', 'pagination')); } public function userShow(Request $request, $id) diff --git a/resources/views/admin/users/home.blade.php b/resources/views/admin/users/home.blade.php index 70fb7df7d..47934dbee 100644 --- a/resources/views/admin/users/home.blade.php +++ b/resources/views/admin/users/home.blade.php @@ -1,16 +1,19 @@ @extends('admin.partial.template-full') -@section('header') -
-
-
test
-
-
-@endsection - @section('section') -
+

Users

+
+ +
+ +
+ +
+
+

@@ -36,7 +39,6 @@ {{$user->id}} - {{$user->username}} @@ -53,7 +55,6 @@ {{$user->id}} - {{$user->username}} @if($user->is_admin) @@ -63,7 +64,7 @@ - + Profile @@ -71,8 +72,8 @@ Review - - Mod Logs + + Mod Tools @@ -83,7 +84,14 @@
- {{$users->links()}} +
@endsection From 53042d295e0b617438719c7d70a25e1fa1d57f71 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 22 Feb 2021 23:05:52 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d8f202e6..e82316fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - Updated Timeline component, add inline reports modal. ([e64b4bd3](https://github.com/pixelfed/pixelfed/commit/e64b4bd3)) - Updated federation pipeline, add locks. ([ddc76887](https://github.com/pixelfed/pixelfed/commit/ddc76887)) - Updated MediaStorageService, improve head checks to fix failed jobs. ([1769cdfd](https://github.com/pixelfed/pixelfed/commit/1769cdfd)) +- Updated user admin, remove expensive db query and add search. ([8feeadbf](https://github.com/pixelfed/pixelfed/commit/8feeadbf)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)