From ece23d751b7a6919389bf598b80249793794c028 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 16 May 2025 03:46:42 -0600 Subject: [PATCH] Update Places, improve cache invalidation/ttl --- app/Http/Controllers/ComposeController.php | 2 + app/Http/Controllers/PlaceController.php | 19 +++------- app/Services/PlaceService.php | 37 +++++++++++++++++++ .../views/discover/places/show.blade.php | 8 ++-- 4 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 app/Services/PlaceService.php diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index f559cd27b..07cea727c 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -19,6 +19,7 @@ use App\Services\MediaBlocklistService; use App\Services\MediaPathService; use App\Services\MediaStorageService; use App\Services\MediaTagService; +use App\Services\PlaceService; use App\Services\SnowflakeService; use App\Services\UserRoleService; use App\Services\UserStorageService; @@ -568,6 +569,7 @@ class ComposeController extends Controller if ($place && is_array($place)) { $status->place_id = $place['id']; + PlaceService::clearStatusesByPlaceId($place['id']); } if ($request->filled('comments_disabled')) { diff --git a/app/Http/Controllers/PlaceController.php b/app/Http/Controllers/PlaceController.php index bafa10dd5..0636863dd 100644 --- a/app/Http/Controllers/PlaceController.php +++ b/app/Http/Controllers/PlaceController.php @@ -3,9 +3,8 @@ namespace App\Http\Controllers; use App\Place; +use App\Services\PlaceService; use App\Services\StatusService; -use App\Status; -use Cache; use Illuminate\Http\Request; class PlaceController extends Controller @@ -17,25 +16,19 @@ class PlaceController extends Controller $this->middleware('auth'); } - public function show(Request $request, $id, $slug) + public function show(Request $request, int $id, $slug) { + abort_if($id < 1 || $id > 128800, 404); + $place = Place::whereSlug($slug)->findOrFail($id); - $statusIds = Cache::remember(self::PLACES_CACHE_KEY.$place->id, now()->addMinutes(40), function () use ($place) { - return Status::select('id') - ->wherePlaceId($place->id) - ->whereScope('public') - ->whereIn('type', ['photo', 'photo:album', 'video']) - ->orderByDesc('id') - ->limit(50) - ->get(); - }); + $statusIds = PlaceService::getStatusesByPlaceId($id); $posts = $statusIds->map(function ($item) { return StatusService::get($item->id); })->filter(function ($item) { return $item && count($item['media_attachments'][0]); - })->take(18)->values(); + })->take(108)->values(); return view('discover.places.show', compact('place', 'posts')); } diff --git a/app/Services/PlaceService.php b/app/Services/PlaceService.php new file mode 100644 index 000000000..e4e6f8e1c --- /dev/null +++ b/app/Services/PlaceService.php @@ -0,0 +1,37 @@ +addDays(4), function () use ($placeId) { + return Status::select('id') + ->wherePlaceId($placeId) + ->whereScope('public') + ->whereIn('type', ['photo', 'photo:album', 'video']) + ->orderByDesc('id') + ->limit(150) + ->get(); + }); + } +} diff --git a/resources/views/discover/places/show.blade.php b/resources/views/discover/places/show.blade.php index 237b2c76b..e0a385987 100644 --- a/resources/views/discover/places/show.blade.php +++ b/resources/views/discover/places/show.blade.php @@ -36,12 +36,12 @@ @endforeach @else
-
-
- +
+
+

No Posts Yet

There are no posts tagged at this location yet.

- + Explore Other Places