|
|
@ -321,14 +321,30 @@ class ComposeController extends Controller
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
$pid = $request->user()->profile_id;
|
|
|
|
$pid = $request->user()->profile_id;
|
|
|
|
abort_if(!$pid, 400);
|
|
|
|
abort_if(!$pid, 400);
|
|
|
|
$q = filter_var($request->input('q'), FILTER_SANITIZE_STRING);
|
|
|
|
$q = e($request->input('q'));
|
|
|
|
$hash = hash('sha256', $q);
|
|
|
|
|
|
|
|
$key = 'pf:search:location:v1:id:' . $hash;
|
|
|
|
$popular = Cache::remember('pf:search:location:v1:popular', 1209600, function() {
|
|
|
|
$popular = Cache::remember('pf:search:location:v1:popular', 86400, function() {
|
|
|
|
|
|
|
|
if(config('database.default') != 'mysql') {
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$minId = SnowflakeService::byDate(now()->subDays(290));
|
|
|
|
$minId = SnowflakeService::byDate(now()->subDays(290));
|
|
|
|
|
|
|
|
if(config('database.default') == 'pgsql') {
|
|
|
|
|
|
|
|
return Status::selectRaw('id, place_id, count(place_id) as pc')
|
|
|
|
|
|
|
|
->whereNotNull('place_id')
|
|
|
|
|
|
|
|
->where('id', '>', $minId)
|
|
|
|
|
|
|
|
->orderByDesc('pc')
|
|
|
|
|
|
|
|
->groupBy(['place_id', 'id'])
|
|
|
|
|
|
|
|
->limit(400)
|
|
|
|
|
|
|
|
->get()
|
|
|
|
|
|
|
|
->filter(function($post) {
|
|
|
|
|
|
|
|
return $post;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
->map(function($place) {
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'id' => $place->place_id,
|
|
|
|
|
|
|
|
'count' => $place->pc
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
->unique('id')
|
|
|
|
|
|
|
|
->values();
|
|
|
|
|
|
|
|
}
|
|
|
|
return Status::selectRaw('id, place_id, count(place_id) as pc')
|
|
|
|
return Status::selectRaw('id, place_id, count(place_id) as pc')
|
|
|
|
->whereNotNull('place_id')
|
|
|
|
->whereNotNull('place_id')
|
|
|
|
->where('id', '>', $minId)
|
|
|
|
->where('id', '>', $minId)
|
|
|
@ -346,30 +362,30 @@ class ComposeController extends Controller
|
|
|
|
];
|
|
|
|
];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$places = Cache::remember($key, 900, function() use($q, $popular) {
|
|
|
|
$q = '%' . $q . '%';
|
|
|
|
$q = '%' . $q . '%';
|
|
|
|
$wildcard = config('database.default') === 'pgsql' ? 'ilike' : 'like';
|
|
|
|
return DB::table('places')
|
|
|
|
|
|
|
|
->where('name', 'like', $q)
|
|
|
|
$places = DB::table('places')
|
|
|
|
->limit((strlen($q) > 5 ? 360 : 180))
|
|
|
|
->where('name', $wildcard, $q)
|
|
|
|
->get()
|
|
|
|
->limit((strlen($q) > 5 ? 360 : 30))
|
|
|
|
->sortByDesc(function($place, $key) use($popular) {
|
|
|
|
->get()
|
|
|
|
return $popular->filter(function($p) use($place) {
|
|
|
|
->sortByDesc(function($place, $key) use($popular) {
|
|
|
|
return $p['id'] == $place->id;
|
|
|
|
return $popular->filter(function($p) use($place) {
|
|
|
|
})->map(function($p) use($place) {
|
|
|
|
return $p['id'] == $place->id;
|
|
|
|
return in_array($place->country, ['Canada', 'USA', 'France', 'Germany', 'United Kingdom']) ? $p['count'] : 1;
|
|
|
|
})->map(function($p) use($place) {
|
|
|
|
})->values();
|
|
|
|
return in_array($place->country, ['Canada', 'USA', 'France', 'Germany', 'United Kingdom']) ? $p['count'] : 1;
|
|
|
|
})
|
|
|
|
})->values();
|
|
|
|
->map(function($r) {
|
|
|
|
})
|
|
|
|
return [
|
|
|
|
->map(function($r) {
|
|
|
|
'id' => $r->id,
|
|
|
|
return [
|
|
|
|
'name' => $r->name,
|
|
|
|
'id' => $r->id,
|
|
|
|
'country' => $r->country,
|
|
|
|
'name' => $r->name,
|
|
|
|
'url' => url('/discover/places/' . $r->id . '/' . $r->slug)
|
|
|
|
'country' => $r->country,
|
|
|
|
];
|
|
|
|
'url' => url('/discover/places/' . $r->id . '/' . $r->slug)
|
|
|
|
})
|
|
|
|
];
|
|
|
|
->values()
|
|
|
|
})
|
|
|
|
->all();
|
|
|
|
->values()
|
|
|
|
});
|
|
|
|
->all();
|
|
|
|
return $places;
|
|
|
|
return $places;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|