Good day sir @Saurabh , my developer have working lazy loading front and backend, so far get under 1 seconds but he have no idea and need get advice from you as so far he has disabled the inactive restaurants listing and added pagination logic and why some restaurants in certain city when test is missing not showing at homepage but when check and search at explore section, we can found that restaurants,
this is edited at restaurantcontroller.php, specifically at:
public function getDeliveryRestaurants(Request $request)
{
// Cache::forget('stores-delivery-active');
// Cache::forget('stores-delivery-inactive');
// die();
/*$allRestaurants = Restaurant::where('is_accepted', 1)->whereIn('is_active', [0, 1])->whereIn('delivery_type', [1, 3])->get();
$nearMeAll = new Collection();
foreach ($allRestaurants as $restaurant) {
$distance = $this->getDistance($request->latitude, $request->longitude, $restaurant->latitude, $restaurant->longitude);
$restaurant->distance = $distance;
$check = $this->checkOperation($request->latitude, $request->longitude, $restaurant);
if ($check) {
$nearMeAll->push($restaurant);
}
}
$nearMeAll = $nearMeAll->map(function ($restaurant) {
$restaurant->avgRating = storeAvgRating($restaurant->ratings);
return $restaurant->only(['id']);
});
$nearMeAll = $nearMe->toArray();*/
$activeStartIndex = $request->activeStartIndex !== null ? $request->activeStartIndex : 0;
$inActiveStartIndex = $request->inActiveStartIndex !== null ? $request->inActiveStartIndex : 0;
$count = $request->count !== null ? $request->count : 50;
// dd($activeStartIndex, $inActiveStartIndex, $count);
// get all active restauants doing delivery
if (Cache::has('stores-delivery-active')) {
$restaurants = Cache::get('stores-delivery-active');
} else {
$restaurantQuery = Restaurant::where('is_accepted', '1')
->where('is_active', 1)
->whereIn('delivery_type', [1, 3])
->with('delivery_areas', 'ratings')
->ordered();
$restaurantsCount = $restaurantQuery->count();
// $restaurants = $restaurantQuery->skip($activeStartIndex)->take($count)->get();
$restaurants = $restaurantQuery->paginate(30);
$this->processSuperCache('stores-delivery-active', $restaurants);
}
//Create a new Laravel collection from the array data
$nearMe = new Collection();
foreach ($restaurants as $restaurant) {
$distance = $this->getDistance($request->latitude, $request->longitude, $restaurant->latitude, $restaurant->longitude);
$restaurant->distance = $distance;
$check = $this->checkOperation($request->latitude, $request->longitude, $restaurant);
if ($check) {
$nearMe->push($restaurant);
}
}
$nearMe = $nearMe->map(function ($restaurant) {
$restaurant->avgRating = storeAvgRating($restaurant->ratings);
return $restaurant->only(['id', 'name', 'description', 'image', 'rating', 'avgRating', 'delivery_time', 'price_range', 'slug', 'is_featured', 'is_active', 'distance', 'custom_featured_name']);
});
$nearMe = $nearMe->toArray();
if (config('appSettings.randomizeStores') == 'true') {
shuffle($nearMe);
usort($nearMe, function ($left, $right) {
return $right['is_featured'] - $left['is_featured'];
});
}
if (config('appSettings.sortDeliveryStoresByDistance') == 'true') {
$nearMe = collect($nearMe)->sortBy('distance')->toArray();
}
/* $nearMeInActive = [];
$nearMeInActive = new Collection();
if (Cache::has('stores-delivery-inactive')) {
$inactiveRestaurants = Cache::get('stores-delivery-inactive');
} else {
$inactiveRestaurants = Restaurant::where('is_accepted', '1')
->where('is_active', 0)
->whereIn('delivery_type', [1, 3])
->with('delivery_areas', 'ratings')
->ordered()
->skip($inActiveStartIndex)->take($count)->get();
$this->processSuperCache('stores-delivery-inactive', $inactiveRestaurants);
}
foreach ($inactiveRestaurants as $inactiveRestaurant) {
$distance = $this->getDistance($request->latitude, $request->longitude, $inactiveRestaurant->latitude, $inactiveRestaurant->longitude);
$inactiveRestaurant->distance = $distance;
$check = $this->checkOperation($request->latitude, $request->longitude, $inactiveRestaurant);
if ($check) {
$nearMeInActive->push($inactiveRestaurant);
}
}
$nearMeInActive = $nearMeInActive->map(function ($restaurant) {
$restaurant->avgRating = storeAvgRating($restaurant->ratings);
return $restaurant->only(['id', 'name', 'description', 'image', 'rating', 'avgRating', 'delivery_time', 'price_range', 'slug', 'is_featured', 'is_active', 'distance', 'custom_featured_name']);
});
$nearMeInActive = $nearMeInActive->toArray();
if (config('appSettings.sortDeliveryStoresByDistance') == 'true') {
$nearMeInActive = collect($nearMeInActive)->sortBy('distance')->toArray();
} */
$data = array_merge($nearMe, []);
// $data = count($nearMe) > 10 ? $nearMe : array_merge($nearMe, $nearMeInActive);
// $merged = array_merge($nearMe, $nearMeInActive);
$meta = [
'start' => 0,
'count' => $count,
'total' => count($data),
'inActiveLength' => !count($data),
'activeLength' => count($data),
'totalActive' => $restaurantsCount,
];
return response()->json(['restaurants' => $data, 'meta' => $meta]);
}
/**
* @param Request $request
* @return mixed
*/
can u when free time check and give some idea?
thanks sir