kopia lustrzana https://github.com/pixelfed/pixelfed
				
				
				
			Update Places, improve cache invalidation/ttl
							rodzic
							
								
									49fb210455
								
							
						
					
					
						commit
						ece23d751b
					
				|  | @ -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')) { | ||||
|  |  | |||
|  | @ -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')); | ||||
|     } | ||||
|  |  | |||
|  | @ -0,0 +1,37 @@ | |||
| <?php | ||||
| 
 | ||||
| namespace App\Services; | ||||
| 
 | ||||
| use App\Status; | ||||
| use Cache; | ||||
| 
 | ||||
| class PlaceService | ||||
| { | ||||
|     const STATUSES_CACHE_KEY = 'pf:places:v0:sid-cache:by:placeid:'; | ||||
| 
 | ||||
|     public static function clearStatusesByPlaceId($placeId = false) | ||||
|     { | ||||
|         if (! $placeId) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         return Cache::forget(self::STATUSES_CACHE_KEY.$placeId); | ||||
|     } | ||||
| 
 | ||||
|     public static function getStatusesByPlaceId($placeId = false) | ||||
|     { | ||||
|         if (! $placeId) { | ||||
|             return []; | ||||
|         } | ||||
| 
 | ||||
|         return Cache::remember(self::STATUSES_CACHE_KEY.$placeId, now()->addDays(4), function () use ($placeId) { | ||||
|             return Status::select('id') | ||||
|                 ->wherePlaceId($placeId) | ||||
|                 ->whereScope('public') | ||||
|                 ->whereIn('type', ['photo', 'photo:album', 'video']) | ||||
|                 ->orderByDesc('id') | ||||
|                 ->limit(150) | ||||
|                 ->get(); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | @ -36,12 +36,12 @@ | |||
|                 @endforeach | ||||
|             @else | ||||
|              <div class="col-12"> | ||||
|                     <div class="card shadow-sm border text-center py-5"> | ||||
|                         <div class="card-body"> | ||||
|                             <i class="far fa-images fa-4x text-muted mb-3"></i> | ||||
|                     <div class="text-center border rounded py-5"> | ||||
|                         <div class=""> | ||||
|                             <i class="far fa-exclamation-triangle fa-4x text-lighter mb-3"></i> | ||||
|                             <h4>No Posts Yet</h4> | ||||
|                             <p class="text-muted">There are no posts tagged at this location yet.</p> | ||||
|                             <a href="/discover/places" class="btn btn-primary mt-2"> | ||||
|                             <a href="/discover/places" class="btn btn-outline-primary font-weight-bold rounded-pill mt-2"> | ||||
|                                 Explore Other Places | ||||
|                             </a> | ||||
|                         </div> | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Daniel Supernault
						Daniel Supernault