mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Update SettingsController, fix double json encoding and cache settings for 7 days
This commit is contained in:
parent
ef0d1f84ae
commit
4514ab1dbe
3 changed files with 60 additions and 20 deletions
|
@ -303,7 +303,7 @@ class SettingsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if($changed) {
|
if($changed) {
|
||||||
$setting->compose_settings = json_encode($compose);
|
$setting->compose_settings = $compose;
|
||||||
$setting->save();
|
$setting->save();
|
||||||
Cache::forget('profile:compose:settings:' . $request->user()->id);
|
Cache::forget('profile:compose:settings:' . $request->user()->id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ class AccountService
|
||||||
|
|
||||||
public static function settings($id)
|
public static function settings($id)
|
||||||
{
|
{
|
||||||
|
return Cache::remember('profile:compose:settings:' . $id, 604800, function() use($id) {
|
||||||
$settings = UserSetting::whereUserId($id)->first();
|
$settings = UserSetting::whereUserId($id)->first();
|
||||||
if(!$settings) {
|
if(!$settings) {
|
||||||
return self::defaultSettings();
|
return self::defaultSettings();
|
||||||
|
@ -96,6 +97,7 @@ class AccountService
|
||||||
}
|
}
|
||||||
return $item;
|
return $item;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canEmbed($id)
|
public static function canEmbed($id)
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use App\UserSetting;
|
||||||
|
|
||||||
|
class FixDoubleJsonEncodedSettingsInUsersettingsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
UserSetting::whereNotNull('compose_settings')
|
||||||
|
->chunk(50, function($settings) {
|
||||||
|
foreach($settings as $userSetting) {
|
||||||
|
if(is_array($userSetting->compose_settings)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$userSetting->compose_settings = json_decode($userSetting->compose_settings);
|
||||||
|
$userSetting->save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue