mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +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->visibility = 'public';
|
||||
$status->save();
|
||||
StatusService::del($status->id);
|
||||
StatusService::del($status->id, true);
|
||||
}
|
||||
});
|
||||
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
||||
|
@ -363,7 +363,7 @@ trait AdminReportController
|
|||
|
||||
$appeal->appeal_handled_at = now();
|
||||
$appeal->save();
|
||||
StatusService::del($status->id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('admin-dash:reports:ai-count');
|
||||
|
||||
return redirect('/i/admin/reports/appeals');
|
||||
|
@ -413,20 +413,20 @@ trait AdminReportController
|
|||
$item->is_nsfw = true;
|
||||
$item->save();
|
||||
$report->nsfw = true;
|
||||
StatusService::del($item->id);
|
||||
StatusService::del($item->id, true);
|
||||
break;
|
||||
|
||||
case 'unlist':
|
||||
$item->visibility = 'unlisted';
|
||||
$item->save();
|
||||
Cache::forget('profiles:private');
|
||||
StatusService::del($item->id);
|
||||
StatusService::del($item->id, true);
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
// Todo: fire delete job
|
||||
$report->admin_seen = null;
|
||||
StatusService::del($item->id);
|
||||
StatusService::del($item->id, true);
|
||||
break;
|
||||
|
||||
case 'shadowban':
|
||||
|
|
|
@ -304,7 +304,7 @@ class BaseApiController extends Controller
|
|||
$status->scope = 'archived';
|
||||
$status->visibility = 'draft';
|
||||
$status->save();
|
||||
StatusService::del($status->id);
|
||||
StatusService::del($status->id, true);
|
||||
AccountService::syncPostCount($status->profile_id);
|
||||
|
||||
return [200];
|
||||
|
@ -331,7 +331,7 @@ class BaseApiController extends Controller
|
|||
$status->visibility = $archive->original_scope;
|
||||
$status->save();
|
||||
$archive->delete();
|
||||
StatusService::del($status->id);
|
||||
StatusService::del($status->id, true);
|
||||
AccountService::syncPostCount($status->profile_id);
|
||||
|
||||
return [200];
|
||||
|
|
|
@ -333,7 +333,7 @@ class InternalApiController extends Controller
|
|||
break;
|
||||
}
|
||||
|
||||
StatusService::del($status->id);
|
||||
StatusService::del($status->id, true);
|
||||
return ['msg' => 200];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,11 @@ use App\AccountInterstitial;
|
|||
use App\Media;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use App\StatusArchived;
|
||||
use App\StatusView;
|
||||
use App\Transformer\ActivityPub\StatusTransformer;
|
||||
use App\Transformer\ActivityPub\Verb\Note;
|
||||
use App\Transformer\ActivityPub\Verb\Question;
|
||||
use App\User;
|
||||
use Auth, DB, Cache;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -81,16 +83,7 @@ class StatusController extends Controller
|
|||
|
||||
public function shortcodeRedirect(Request $request, $id)
|
||||
{
|
||||
abort_if(strlen($id) < 5, 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());
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function showId(int $id)
|
||||
|
@ -215,7 +208,7 @@ class StatusController extends Controller
|
|||
Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
|
||||
Cache::forget('profile:status_count:' . $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) {
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
StatusDelete::dispatch($status);
|
||||
|
@ -278,8 +271,9 @@ class StatusController extends Controller
|
|||
|
||||
public function showActivityPub(Request $request, $status)
|
||||
{
|
||||
$object = $status->type == 'poll' ? new Question() : new Note();
|
||||
$fractal = new Fractal\Manager();
|
||||
$resource = new Fractal\Resource\Item($status, new Note());
|
||||
$resource = new Fractal\Resource\Item($status, $object);
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
|
||||
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->visibility = $status->scope;
|
||||
$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\Redis;
|
||||
use DB;
|
||||
use App\Status;
|
||||
//use App\Transformer\Api\v3\StatusTransformer;
|
||||
use App\Transformer\Api\StatusStatelessTransformer;
|
||||
|
@ -12,8 +13,8 @@ use League\Fractal;
|
|||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
|
||||
class StatusService {
|
||||
|
||||
class StatusService
|
||||
{
|
||||
const CACHE_KEY = 'pf:services:status:';
|
||||
|
||||
public static function key($id, $publicOnly = true)
|
||||
|
@ -61,18 +62,22 @@ class StatusService {
|
|||
return $fractal->createData($resource)->toArray();
|
||||
}
|
||||
|
||||
public static function del($id)
|
||||
public static function del($id, $purge = false)
|
||||
{
|
||||
$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));
|
||||
return Cache::forget(self::key($id));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue