mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update StatusService, improve cache invalidation
This commit is contained in:
parent
c2910e5d42
commit
83b48b5681
6 changed files with 31 additions and 32 deletions
|
@ -296,7 +296,7 @@ trait AdminReportController
|
||||||
$status->scope = 'public';
|
$status->scope = 'public';
|
||||||
$status->visibility = 'public';
|
$status->visibility = 'public';
|
||||||
$status->save();
|
$status->save();
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
||||||
|
@ -363,7 +363,7 @@ trait AdminReportController
|
||||||
|
|
||||||
$appeal->appeal_handled_at = now();
|
$appeal->appeal_handled_at = now();
|
||||||
$appeal->save();
|
$appeal->save();
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
Cache::forget('admin-dash:reports:ai-count');
|
Cache::forget('admin-dash:reports:ai-count');
|
||||||
|
|
||||||
return redirect('/i/admin/reports/appeals');
|
return redirect('/i/admin/reports/appeals');
|
||||||
|
@ -413,20 +413,20 @@ trait AdminReportController
|
||||||
$item->is_nsfw = true;
|
$item->is_nsfw = true;
|
||||||
$item->save();
|
$item->save();
|
||||||
$report->nsfw = true;
|
$report->nsfw = true;
|
||||||
StatusService::del($item->id);
|
StatusService::del($item->id, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'unlist':
|
case 'unlist':
|
||||||
$item->visibility = 'unlisted';
|
$item->visibility = 'unlisted';
|
||||||
$item->save();
|
$item->save();
|
||||||
Cache::forget('profiles:private');
|
Cache::forget('profiles:private');
|
||||||
StatusService::del($item->id);
|
StatusService::del($item->id, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
// Todo: fire delete job
|
// Todo: fire delete job
|
||||||
$report->admin_seen = null;
|
$report->admin_seen = null;
|
||||||
StatusService::del($item->id);
|
StatusService::del($item->id, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'shadowban':
|
case 'shadowban':
|
||||||
|
|
|
@ -304,7 +304,7 @@ class BaseApiController extends Controller
|
||||||
$status->scope = 'archived';
|
$status->scope = 'archived';
|
||||||
$status->visibility = 'draft';
|
$status->visibility = 'draft';
|
||||||
$status->save();
|
$status->save();
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
AccountService::syncPostCount($status->profile_id);
|
AccountService::syncPostCount($status->profile_id);
|
||||||
|
|
||||||
return [200];
|
return [200];
|
||||||
|
@ -331,7 +331,7 @@ class BaseApiController extends Controller
|
||||||
$status->visibility = $archive->original_scope;
|
$status->visibility = $archive->original_scope;
|
||||||
$status->save();
|
$status->save();
|
||||||
$archive->delete();
|
$archive->delete();
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
AccountService::syncPostCount($status->profile_id);
|
AccountService::syncPostCount($status->profile_id);
|
||||||
|
|
||||||
return [200];
|
return [200];
|
||||||
|
|
|
@ -333,7 +333,7 @@ class InternalApiController extends Controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
return ['msg' => 200];
|
return ['msg' => 200];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,11 @@ use App\AccountInterstitial;
|
||||||
use App\Media;
|
use App\Media;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
|
use App\StatusArchived;
|
||||||
use App\StatusView;
|
use App\StatusView;
|
||||||
use App\Transformer\ActivityPub\StatusTransformer;
|
use App\Transformer\ActivityPub\StatusTransformer;
|
||||||
use App\Transformer\ActivityPub\Verb\Note;
|
use App\Transformer\ActivityPub\Verb\Note;
|
||||||
|
use App\Transformer\ActivityPub\Verb\Question;
|
||||||
use App\User;
|
use App\User;
|
||||||
use Auth, DB, Cache;
|
use Auth, DB, Cache;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
@ -81,16 +83,7 @@ class StatusController extends Controller
|
||||||
|
|
||||||
public function shortcodeRedirect(Request $request, $id)
|
public function shortcodeRedirect(Request $request, $id)
|
||||||
{
|
{
|
||||||
abort_if(strlen($id) < 5, 404);
|
abort(404);
|
||||||
if(!Auth::check()) {
|
|
||||||
return redirect('/login?next='.urlencode('/' . $request->path()));
|
|
||||||
}
|
|
||||||
$id = HashidService::decode($id);
|
|
||||||
$status = Status::find($id);
|
|
||||||
if(!$status) {
|
|
||||||
return redirect('/404');
|
|
||||||
}
|
|
||||||
return redirect($status->url());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showId(int $id)
|
public function showId(int $id)
|
||||||
|
@ -215,7 +208,7 @@ class StatusController extends Controller
|
||||||
Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
|
Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
|
||||||
Cache::forget('profile:status_count:' . $status->profile_id);
|
Cache::forget('profile:status_count:' . $status->profile_id);
|
||||||
Cache::forget('profile:embed:' . $status->profile_id);
|
Cache::forget('profile:embed:' . $status->profile_id);
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
if ($status->profile_id == $user->profile->id || $user->is_admin == true) {
|
if ($status->profile_id == $user->profile->id || $user->is_admin == true) {
|
||||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||||
StatusDelete::dispatch($status);
|
StatusDelete::dispatch($status);
|
||||||
|
@ -278,8 +271,9 @@ class StatusController extends Controller
|
||||||
|
|
||||||
public function showActivityPub(Request $request, $status)
|
public function showActivityPub(Request $request, $status)
|
||||||
{
|
{
|
||||||
|
$object = $status->type == 'poll' ? new Question() : new Note();
|
||||||
$fractal = new Fractal\Manager();
|
$fractal = new Fractal\Manager();
|
||||||
$resource = new Fractal\Resource\Item($status, new Note());
|
$resource = new Fractal\Resource\Item($status, $object);
|
||||||
$res = $fractal->createData($resource)->toArray();
|
$res = $fractal->createData($resource)->toArray();
|
||||||
|
|
||||||
return response()->json($res['data'], 200, ['Content-Type' => 'application/activity+json'], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
return response()->json($res['data'], 200, ['Content-Type' => 'application/activity+json'], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||||
|
|
|
@ -41,7 +41,7 @@ class HandleSpammerPipeline implements ShouldQueue
|
||||||
$status->scope = $status->scope === 'public' ? 'unlisted' : $status->scope;
|
$status->scope = $status->scope === 'public' ? 'unlisted' : $status->scope;
|
||||||
$status->visibility = $status->scope;
|
$status->visibility = $status->scope;
|
||||||
$status->save();
|
$status->save();
|
||||||
StatusService::del($status->id);
|
StatusService::del($status->id, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Services;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
use DB;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
//use App\Transformer\Api\v3\StatusTransformer;
|
//use App\Transformer\Api\v3\StatusTransformer;
|
||||||
use App\Transformer\Api\StatusStatelessTransformer;
|
use App\Transformer\Api\StatusStatelessTransformer;
|
||||||
|
@ -12,8 +13,8 @@ use League\Fractal;
|
||||||
use League\Fractal\Serializer\ArraySerializer;
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
|
|
||||||
class StatusService {
|
class StatusService
|
||||||
|
{
|
||||||
const CACHE_KEY = 'pf:services:status:';
|
const CACHE_KEY = 'pf:services:status:';
|
||||||
|
|
||||||
public static function key($id, $publicOnly = true)
|
public static function key($id, $publicOnly = true)
|
||||||
|
@ -61,18 +62,22 @@ class StatusService {
|
||||||
return $fractal->createData($resource)->toArray();
|
return $fractal->createData($resource)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function del($id)
|
public static function del($id, $purge = false)
|
||||||
{
|
{
|
||||||
$status = self::get($id);
|
$status = self::get($id);
|
||||||
if($status && isset($status['account']) && isset($status['account']['id'])) {
|
|
||||||
Cache::forget('profile:embed:' . $status['account']['id']);
|
if($purge) {
|
||||||
|
if($status && isset($status['account']) && isset($status['account']['id'])) {
|
||||||
|
Cache::forget('profile:embed:' . $status['account']['id']);
|
||||||
|
}
|
||||||
|
Cache::forget('status:transformer:media:attachments:' . $id);
|
||||||
|
MediaService::del($id);
|
||||||
|
Cache::forget('status:thumb:nsfw0' . $id);
|
||||||
|
Cache::forget('status:thumb:nsfw1' . $id);
|
||||||
|
Cache::forget('pf:services:sh:id:' . $id);
|
||||||
|
PublicTimelineService::rem($id);
|
||||||
}
|
}
|
||||||
Cache::forget('status:transformer:media:attachments:' . $id);
|
|
||||||
MediaService::del($id);
|
|
||||||
Cache::forget('status:thumb:nsfw0' . $id);
|
|
||||||
Cache::forget('status:thumb:nsfw1' . $id);
|
|
||||||
Cache::forget('pf:services:sh:id:' . $id);
|
|
||||||
PublicTimelineService::rem($id);
|
|
||||||
Cache::forget(self::key($id, false));
|
Cache::forget(self::key($id, false));
|
||||||
return Cache::forget(self::key($id));
|
return Cache::forget(self::key($id));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue