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