PlaceService.php 899 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Services;
  3. use App\Status;
  4. use Cache;
  5. class PlaceService
  6. {
  7. const STATUSES_CACHE_KEY = 'pf:places:v0:sid-cache:by:placeid:';
  8. public static function clearStatusesByPlaceId($placeId = false)
  9. {
  10. if (! $placeId) {
  11. return;
  12. }
  13. return Cache::forget(self::STATUSES_CACHE_KEY.$placeId);
  14. }
  15. public static function getStatusesByPlaceId($placeId = false)
  16. {
  17. if (! $placeId) {
  18. return [];
  19. }
  20. return Cache::remember(self::STATUSES_CACHE_KEY.$placeId, now()->addDays(4), function () use ($placeId) {
  21. return Status::select('id')
  22. ->wherePlaceId($placeId)
  23. ->whereScope('public')
  24. ->whereIn('type', ['photo', 'photo:album', 'video'])
  25. ->orderByDesc('id')
  26. ->limit(150)
  27. ->get();
  28. });
  29. }
  30. }