mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Update CollectionController
This commit is contained in:
parent
84e152896b
commit
b8ad594a05
2 changed files with 27 additions and 27 deletions
|
@ -77,6 +77,7 @@ class CollectionController extends Controller
|
|||
$collection->visibility = $request->input('visibility');
|
||||
$collection->save();
|
||||
|
||||
CollectionService::deleteCollection($id);
|
||||
return CollectionService::setCollection($collection->id, $collection);
|
||||
}
|
||||
|
||||
|
@ -93,9 +94,9 @@ class CollectionController extends Controller
|
|||
if($collection->items()->count() == 0) {
|
||||
abort(404);
|
||||
}
|
||||
$collection->title = e($request->input('title'));
|
||||
$collection->title = strip_tags($request->input('title'));
|
||||
$collection->description = strip_tags($request->input('description'));
|
||||
$collection->visibility = strip_tags($request->input('visibility'));
|
||||
$collection->visibility = $request->input('visibility');
|
||||
$collection->published_at = now();
|
||||
$collection->save();
|
||||
return CollectionService::setCollection($collection->id, $collection);
|
||||
|
@ -134,6 +135,7 @@ class CollectionController extends Controller
|
|||
|
||||
$collection = Collection::whereProfileId($profileId)->findOrFail($collectionId);
|
||||
$count = $collection->items()->count();
|
||||
CollectionService::deleteCollection($collection->id);
|
||||
|
||||
if($count) {
|
||||
CollectionItem::whereCollectionId($collection->id)
|
||||
|
@ -301,11 +303,6 @@ class CollectionController extends Controller
|
|||
->whereIn('type', ['photo', 'photo:album', 'video'])
|
||||
->findOrFail($postId);
|
||||
|
||||
CollectionService::removeItem(
|
||||
$collection->id,
|
||||
$status->id
|
||||
);
|
||||
|
||||
$item = CollectionItem::whereCollectionId($collection->id)
|
||||
->whereObjectType('App\Status')
|
||||
->whereObjectId($status->id)
|
||||
|
@ -313,9 +310,17 @@ class CollectionController extends Controller
|
|||
|
||||
$item->delete();
|
||||
|
||||
CollectionItem::whereCollectionId($collection->id)
|
||||
->orderBy('created_at')
|
||||
->get()
|
||||
->each(function($item, $index) {
|
||||
$item->order = $index;
|
||||
$item->save();
|
||||
});
|
||||
|
||||
$collection->updated_at = now();
|
||||
$collection->save();
|
||||
CollectionService::setCollection($collection->id, $collection);
|
||||
CollectionService::deleteCollection($collection->id);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
|
|
@ -22,37 +22,32 @@ class CollectionService
|
|||
|
||||
public static function addItem($id, $sid, $score)
|
||||
{
|
||||
Redis::zadd(self::CACHE_KEY . 'items:' . $id, $score, $sid);
|
||||
return Redis::zadd(self::CACHE_KEY . 'items:' . $id, $score, $sid);
|
||||
}
|
||||
|
||||
public static function removeItem($id, $sid)
|
||||
{
|
||||
Redis::zrem(self::CACHE_KEY . 'items:' . $id, $sid);
|
||||
return Redis::zrem(self::CACHE_KEY . 'items:' . $id, $sid);
|
||||
}
|
||||
|
||||
public static function clearItems($id)
|
||||
{
|
||||
Redis::del(self::CACHE_KEY . 'items:' . $id);
|
||||
return Redis::del(self::CACHE_KEY . 'items:' . $id);
|
||||
}
|
||||
|
||||
public static function coldBootItems($id)
|
||||
{
|
||||
return Cache::remember(self::CACHE_KEY . 'items:' . $id, 86400, function() use($id) {
|
||||
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);
|
||||
return self::addItem($id, $item->object_id, $item->order);
|
||||
})
|
||||
->map(function($item) {
|
||||
return (string) $item->object_id;
|
||||
})
|
||||
->values()
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
public static function count($id)
|
||||
|
|
Loading…
Reference in a new issue