1
0
Fork 0
forked from mirror/pixelfed

Improve CollectionService cache invalidation, fixes #3548

This commit is contained in:
Daniel Supernault 2022-06-18 23:47:16 -06:00
parent 9860b4a735
commit 44f4a9edd9
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
4 changed files with 33 additions and 3 deletions

View file

@ -1,7 +1,6 @@
root = true root = true
[*] [*]
indent_style = space
indent_size = 4 indent_size = 4
end_of_line = lf end_of_line = lf
charset = utf-8 charset = utf-8

View file

@ -132,6 +132,18 @@ class CollectionController extends Controller
$collection = Collection::whereProfileId($profileId)->findOrFail($collectionId); $collection = Collection::whereProfileId($profileId)->findOrFail($collectionId);
$count = $collection->items()->count(); $count = $collection->items()->count();
if($count) {
CollectionItem::whereCollectionId($collection->id)
->get()
->filter(function($col) {
return StatusService::get($col->object_id, false) == null;
})
->each(function($col) use($collectionId) {
CollectionService::removeItem($collectionId, $col->object_id);
$col->delete();
});
}
$max = config('pixelfed.max_collection_length'); $max = config('pixelfed.max_collection_length');
if($count >= $max) { if($count >= $max) {
abort(400, 'You can only add '.$max.' posts per collection'); abort(400, 'You can only add '.$max.' posts per collection');

View file

@ -5,6 +5,7 @@ namespace App\Jobs\StatusPipeline;
use DB, Storage; use DB, Storage;
use App\{ use App\{
AccountInterstitial, AccountInterstitial,
CollectionItem,
MediaTag, MediaTag,
Notification, Notification,
Report, Report,
@ -25,6 +26,7 @@ use GuzzleHttp\Pool;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Promise; use GuzzleHttp\Promise;
use App\Util\ActivityPub\HttpSignature; use App\Util\ActivityPub\HttpSignature;
use App\Services\CollectionService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Services\MediaStorageService; use App\Services\MediaStorageService;
@ -89,6 +91,19 @@ class StatusDelete implements ShouldQueue
$parent->save(); $parent->save();
}); });
} }
DB::transaction(function() use($status) {
CollectionItem::whereObjectType('App\Status')
->whereObjectId($status->id)
->get()
->each(function($col) {
$id = $col->collection_id;
$sid = $col->object_id;
$col->delete();
CollectionService::removeItem($id, $sid);
});
});
DB::transaction(function() use($status) { DB::transaction(function() use($status) {
$comments = Status::where('in_reply_to_id', $status->id)->get(); $comments = Status::where('in_reply_to_id', $status->id)->get();
foreach ($comments as $comment) { foreach ($comments as $comment) {

View file

@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Redis;
class CollectionService class CollectionService
{ {
const CACHE_KEY = 'pf:services:collections:'; const CACHE_KEY = 'pf:services:collections-v1:';
public static function getItems($id, $start = 0, $stop = 10) public static function getItems($id, $start = 0, $stop = 10)
{ {
@ -41,6 +41,9 @@ class CollectionService
return CollectionItem::whereCollectionId($id) return CollectionItem::whereCollectionId($id)
->orderBy('order') ->orderBy('order')
->get() ->get()
->filter(function($item) use($id) {
return StatusService::get($item->object_id) != null;
})
->each(function($item) use ($id) { ->each(function($item) use ($id) {
self::addItem($id, $item->object_id, $item->order); self::addItem($id, $item->object_id, $item->order);
}) })
@ -80,13 +83,14 @@ class CollectionService
'visibility' => $collection->visibility, 'visibility' => $collection->visibility,
'title' => $collection->title, 'title' => $collection->title,
'description' => $collection->description, 'description' => $collection->description,
'thumb' => self::getThumb($id), 'thumb' => '/storage/no-preview.png',
'url' => $collection->url(), 'url' => $collection->url(),
'published_at' => $collection->published_at 'published_at' => $collection->published_at
]; ];
}); });
if($collection) { if($collection) {
$collection['thumb'] = self::getThumb($id);
$collection['post_count'] = self::count($id); $collection['post_count'] = self::count($id);
} }