mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Improve CollectionService cache invalidation, fixes #3548
This commit is contained in:
parent
9860b4a735
commit
44f4a9edd9
4 changed files with 33 additions and 3 deletions
|
@ -1,7 +1,6 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
|
|
|
@ -132,6 +132,18 @@ class CollectionController extends Controller
|
|||
$collection = Collection::whereProfileId($profileId)->findOrFail($collectionId);
|
||||
$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');
|
||||
if($count >= $max) {
|
||||
abort(400, 'You can only add '.$max.' posts per collection');
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Jobs\StatusPipeline;
|
|||
use DB, Storage;
|
||||
use App\{
|
||||
AccountInterstitial,
|
||||
CollectionItem,
|
||||
MediaTag,
|
||||
Notification,
|
||||
Report,
|
||||
|
@ -25,6 +26,7 @@ use GuzzleHttp\Pool;
|
|||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Promise;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\MediaStorageService;
|
||||
|
||||
|
@ -89,6 +91,19 @@ class StatusDelete implements ShouldQueue
|
|||
$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) {
|
||||
$comments = Status::where('in_reply_to_id', $status->id)->get();
|
||||
foreach ($comments as $comment) {
|
||||
|
|
|
@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Redis;
|
|||
|
||||
class CollectionService
|
||||
{
|
||||
const CACHE_KEY = 'pf:services:collections:';
|
||||
const CACHE_KEY = 'pf:services:collections-v1:';
|
||||
|
||||
public static function getItems($id, $start = 0, $stop = 10)
|
||||
{
|
||||
|
@ -41,6 +41,9 @@ class CollectionService
|
|||
return CollectionItem::whereCollectionId($id)
|
||||
->orderBy('order')
|
||||
->get()
|
||||
->filter(function($item) use($id) {
|
||||
return StatusService::get($item->object_id) != null;
|
||||
})
|
||||
->each(function($item) use ($id) {
|
||||
self::addItem($id, $item->object_id, $item->order);
|
||||
})
|
||||
|
@ -80,13 +83,14 @@ class CollectionService
|
|||
'visibility' => $collection->visibility,
|
||||
'title' => $collection->title,
|
||||
'description' => $collection->description,
|
||||
'thumb' => self::getThumb($id),
|
||||
'thumb' => '/storage/no-preview.png',
|
||||
'url' => $collection->url(),
|
||||
'published_at' => $collection->published_at
|
||||
];
|
||||
});
|
||||
|
||||
if($collection) {
|
||||
$collection['thumb'] = self::getThumb($id);
|
||||
$collection['post_count'] = self::count($id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue