Merge pull request #3225 from pixelfed/staging

Staging
This commit is contained in:
daniel 2022-02-09 19:17:13 -07:00 committed by GitHub
commit 8fad40ed26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 11 deletions

View file

@ -37,6 +37,7 @@
- Updated InstanceActorController, fix content-type header. ([21792246](https://github.com/pixelfed/pixelfed/commit/21792246)) - Updated InstanceActorController, fix content-type header. ([21792246](https://github.com/pixelfed/pixelfed/commit/21792246))
- Updated Exception handler to report validation message bag errors. ([74905ba1](https://github.com/pixelfed/pixelfed/commit/74905ba1)) - Updated Exception handler to report validation message bag errors. ([74905ba1](https://github.com/pixelfed/pixelfed/commit/74905ba1))
- Updated ApiV1Controller, add validation messages to update_credentials endpoint. ([cd785601](https://github.com/pixelfed/pixelfed/commit/cd785601)) - Updated ApiV1Controller, add validation messages to update_credentials endpoint. ([cd785601](https://github.com/pixelfed/pixelfed/commit/cd785601))
- Updated ComposeController, improve location search results ordering by use frequency. ([29c4bd25](https://github.com/pixelfed/pixelfed/commit/29c4bd25))
- ([](https://github.com/pixelfed/pixelfed/commit/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2)

View file

@ -3,7 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Auth, Cache, Storage, URL; use Auth, Cache, DB, Storage, URL;
use Carbon\Carbon; use Carbon\Carbon;
use App\{ use App\{
Avatar, Avatar,
@ -45,10 +45,12 @@ use App\Services\MediaBlocklistService;
use App\Services\MediaStorageService; use App\Services\MediaStorageService;
use App\Services\MediaTagService; use App\Services\MediaTagService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Services\SnowflakeService;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Util\Lexer\Autolink; use App\Util\Lexer\Autolink;
use App\Util\Lexer\Extractor; use App\Util\Lexer\Extractor;
use App\Util\Media\License; use App\Util\Media\License;
use Image;
class ComposeController extends Controller class ComposeController extends Controller
{ {
@ -74,7 +76,7 @@ class ComposeController extends Controller
'file.*' => function() { 'file.*' => function() {
return [ return [
'required', 'required',
'mimes:' . config_cache('pixelfed.media_types'), 'mimetypes:' . config_cache('pixelfed.media_types'),
'max:' . config_cache('pixelfed.max_photo_size'), 'max:' . config_cache('pixelfed.max_photo_size'),
]; ];
}, },
@ -169,7 +171,7 @@ class ComposeController extends Controller
'file' => function() { 'file' => function() {
return [ return [
'required', 'required',
'mimes:' . config_cache('pixelfed.media_types'), 'mimetypes:' . config_cache('pixelfed.media_types'),
'max:' . config_cache('pixelfed.max_photo_size'), 'max:' . config_cache('pixelfed.max_photo_size'),
]; ];
}, },
@ -313,22 +315,56 @@ class ComposeController extends Controller
$this->validate($request, [ $this->validate($request, [
'q' => 'required|string|max:100' 'q' => 'required|string|max:100'
]); ]);
$pid = $request->user()->profile_id;
abort_if(!$pid, 400);
$q = filter_var($request->input('q'), FILTER_SANITIZE_STRING); $q = filter_var($request->input('q'), FILTER_SANITIZE_STRING);
$hash = hash('sha256', $q); $hash = hash('sha256', $q);
$key = 'search:location:id:' . $hash; $key = 'pf:search:location:v1:id:' . $hash;
$places = Cache::remember($key, now()->addMinutes(15), function() use($q) { $popular = Cache::remember('pf:search:location:v1:popular', 86400, function() {
if(config('database.default') != 'mysql') {
return [];
}
$minId = SnowflakeService::byDate(now()->subDays(290));
return Status::selectRaw('id, place_id, count(place_id) as pc')
->whereNotNull('place_id')
->where('id', '>', $minId)
->groupBy('place_id')
->orderByDesc('pc')
->limit(400)
->get()
->filter(function($post) {
return $post;
})
->map(function($place) {
return [
'id' => $place->place_id,
'count' => $place->pc
];
});
});
$places = Cache::remember($key, 900, function() use($q, $popular) {
$q = '%' . $q . '%'; $q = '%' . $q . '%';
return Place::where('name', 'like', $q) return DB::table('places')
->take(80) ->where('name', 'like', $q)
->limit((strlen($q) > 5 ? 360 : 180))
->get() ->get()
->sortByDesc(function($place, $key) use($popular) {
return $popular->filter(function($p) use($place) {
return $p['id'] == $place->id;
})->map(function($p) use($place) {
return in_array($place->country, ['Canada', 'USA', 'France', 'Germany', 'United Kingdom']) ? $p['count'] : 1;
})->values();
})
->map(function($r) { ->map(function($r) {
return [ return [
'id' => $r->id, 'id' => $r->id,
'name' => $r->name, 'name' => $r->name,
'country' => $r->country, 'country' => $r->country,
'url' => $r->url() 'url' => url('/discover/places/' . $r->id . '/' . $r->slug)
]; ];
}); })
->values()
->all();
}); });
return $places; return $places;
} }

View file

@ -257,7 +257,9 @@ class SettingsController extends Controller
public function mediaSettings(Request $request) public function mediaSettings(Request $request)
{ {
$setting = UserSetting::whereUserId($request->user()->id)->firstOrFail(); $setting = UserSetting::whereUserId($request->user()->id)->firstOrFail();
$compose = $setting->compose_settings ? json_decode($setting->compose_settings, true) : [ $compose = $setting->compose_settings ? (
is_string($setting->compose_settings) ? json_decode($setting->compose_settings, true) : $setting->compose_settings
) : [
'default_license' => null, 'default_license' => null,
'media_descriptions' => false 'media_descriptions' => false
]; ];
@ -278,7 +280,7 @@ class SettingsController extends Controller
$uid = $request->user()->id; $uid = $request->user()->id;
$setting = UserSetting::whereUserId($uid)->firstOrFail(); $setting = UserSetting::whereUserId($uid)->firstOrFail();
$compose = json_decode($setting->compose_settings, true); $compose = is_string($setting->compose_settings) ? json_decode($setting->compose_settings, true) : $setting->compose_settings;
$changed = false; $changed = false;
if($sync) { if($sync) {