mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 16:44:50 +00:00
Merge pull request #4263 from pixelfed/staging
Update ComposeController, fix postgres location search. Closes #4242 …
This commit is contained in:
commit
8458eb9c7e
2 changed files with 48 additions and 31 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
### Updates
|
### Updates
|
||||||
- Update ApiV1Controller, fix blocking remote accounts. Closes #4256 ([8e71e0c0](https://github.com/pixelfed/pixelfed/commit/8e71e0c0))
|
- Update ApiV1Controller, fix blocking remote accounts. Closes #4256 ([8e71e0c0](https://github.com/pixelfed/pixelfed/commit/8e71e0c0))
|
||||||
|
- Update ComposeController, fix postgres location search. Closes #4242 and #4239 ([64a4a006](https://github.com/pixelfed/pixelfed/commit/64a4a006))
|
||||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||||
|
|
||||||
## [v0.11.5 (2023-03-25)](https://github.com/pixelfed/pixelfed/compare/v0.11.4...v0.11.5)
|
## [v0.11.5 (2023-03-25)](https://github.com/pixelfed/pixelfed/compare/v0.11.4...v0.11.5)
|
||||||
|
|
|
@ -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,11 +362,12 @@ class ComposeController extends Controller
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$places = Cache::remember($key, 900, function() use($q, $popular) {
|
|
||||||
$q = '%' . $q . '%';
|
$q = '%' . $q . '%';
|
||||||
return DB::table('places')
|
$wildcard = config('database.default') === 'pgsql' ? 'ilike' : 'like';
|
||||||
->where('name', 'like', $q)
|
|
||||||
->limit((strlen($q) > 5 ? 360 : 180))
|
$places = DB::table('places')
|
||||||
|
->where('name', $wildcard, $q)
|
||||||
|
->limit((strlen($q) > 5 ? 360 : 30))
|
||||||
->get()
|
->get()
|
||||||
->sortByDesc(function($place, $key) use($popular) {
|
->sortByDesc(function($place, $key) use($popular) {
|
||||||
return $popular->filter(function($p) use($place) {
|
return $popular->filter(function($p) use($place) {
|
||||||
|
@ -369,7 +386,6 @@ class ComposeController extends Controller
|
||||||
})
|
})
|
||||||
->values()
|
->values()
|
||||||
->all();
|
->all();
|
||||||
});
|
|
||||||
return $places;
|
return $places;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue