mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update FollowPipeline, fix cache invalidation bug
This commit is contained in:
parent
1060dd23d5
commit
c1f14f89f6
1 changed files with 51 additions and 48 deletions
|
@ -14,59 +14,62 @@ use Illuminate\Support\Facades\Redis;
|
||||||
|
|
||||||
class FollowPipeline implements ShouldQueue
|
class FollowPipeline implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
protected $follower;
|
protected $follower;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the job if its models no longer exist.
|
* Delete the job if its models no longer exist.
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $deleteWhenMissingModels = true;
|
public $deleteWhenMissingModels = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($follower)
|
public function __construct($follower)
|
||||||
{
|
{
|
||||||
$this->follower = $follower;
|
$this->follower = $follower;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$follower = $this->follower;
|
$follower = $this->follower;
|
||||||
$actor = $follower->actor;
|
$actor = $follower->actor;
|
||||||
$target = $follower->target;
|
$target = $follower->target;
|
||||||
|
|
||||||
if($target->domain || !$target->private_key) {
|
Cache::forget('profile:following:' . $actor->id);
|
||||||
return;
|
Cache::forget('profile:following:' . $target->id);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
if($target->domain || !$target->private_key) {
|
||||||
$notification = new Notification();
|
return;
|
||||||
$notification->profile_id = $target->id;
|
}
|
||||||
$notification->actor_id = $actor->id;
|
|
||||||
$notification->action = 'follow';
|
|
||||||
$notification->message = $follower->toText();
|
|
||||||
$notification->rendered = $follower->toHtml();
|
|
||||||
$notification->item_id = $target->id;
|
|
||||||
$notification->item_type = "App\Profile";
|
|
||||||
$notification->save();
|
|
||||||
|
|
||||||
$redis = Redis::connection();
|
try {
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification->profile_id = $target->id;
|
||||||
|
$notification->actor_id = $actor->id;
|
||||||
|
$notification->action = 'follow';
|
||||||
|
$notification->message = $follower->toText();
|
||||||
|
$notification->rendered = $follower->toHtml();
|
||||||
|
$notification->item_id = $target->id;
|
||||||
|
$notification->item_type = "App\Profile";
|
||||||
|
$notification->save();
|
||||||
|
|
||||||
$nkey = config('cache.prefix').':user.'.$target->id.'.notifications';
|
$redis = Redis::connection();
|
||||||
$redis->lpush($nkey, $notification->id);
|
|
||||||
} catch (Exception $e) {
|
$nkey = config('cache.prefix').':user.'.$target->id.'.notifications';
|
||||||
Log::error($e);
|
$redis->lpush($nkey, $notification->id);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
}
|
Log::error($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue