mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 09:17:03 +00:00
Update ApiController, fixes #1705
This commit is contained in:
parent
788f76cf35
commit
139c6651bf
1 changed files with 16 additions and 12 deletions
|
@ -83,20 +83,24 @@ class ApiController extends BaseApiController
|
||||||
{
|
{
|
||||||
abort_if(!Auth::check(), 403);
|
abort_if(!Auth::check(), 403);
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'q' => 'required|string'
|
'q' => 'required|string|max:100'
|
||||||
]);
|
]);
|
||||||
$q = filter_var($request->input('q'), FILTER_SANITIZE_STRING);
|
$q = filter_var($request->input('q'), FILTER_SANITIZE_STRING);
|
||||||
$q = '%' . $q . '%';
|
$hash = hash('sha256', $q);
|
||||||
$places = Place::where('name', 'like', $q)
|
$key = 'search:location:id:' . $hash;
|
||||||
->take(25)
|
$places = Cache::remember($key, now()->addMinutes(15), function() use($q) {
|
||||||
->get()
|
$q = '%' . $q . '%';
|
||||||
->map(function($r) {
|
return Place::where('name', 'like', $q)
|
||||||
return [
|
->take(80)
|
||||||
'id' => $r->id,
|
->get()
|
||||||
'name' => $r->name,
|
->map(function($r) {
|
||||||
'country' => $r->country,
|
return [
|
||||||
'url' => $r->url()
|
'id' => $r->id,
|
||||||
];
|
'name' => $r->name,
|
||||||
|
'country' => $r->country,
|
||||||
|
'url' => $r->url()
|
||||||
|
];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return $places;
|
return $places;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue