HashtagRemoveFanoutPipeline.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Jobs\HomeFeedPipeline;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Hashtag;
  10. use App\StatusHashtag;
  11. use App\Services\HashtagFollowService;
  12. use App\Services\HomeTimelineService;
  13. use App\Services\StatusService;
  14. use Illuminate\Queue\Middleware\WithoutOverlapping;
  15. use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
  16. class HashtagRemoveFanoutPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  17. {
  18. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19. protected $sid;
  20. protected $hid;
  21. public $timeout = 900;
  22. public $tries = 3;
  23. public $maxExceptions = 1;
  24. public $failOnTimeout = true;
  25. /**
  26. * The number of seconds after which the job's unique lock will be released.
  27. *
  28. * @var int
  29. */
  30. public $uniqueFor = 3600;
  31. /**
  32. * Get the unique ID for the job.
  33. */
  34. public function uniqueId(): string
  35. {
  36. return 'hfp:hashtag:fanout:remove:' . $this->hid . ':' . $this->sid;
  37. }
  38. /**
  39. * Get the middleware the job should pass through.
  40. *
  41. * @return array<int, object>
  42. */
  43. public function middleware(): array
  44. {
  45. return [(new WithoutOverlapping("hfp:hashtag:fanout:remove:{$this->hid}:{$this->sid}"))->shared()->dontRelease()];
  46. }
  47. /**
  48. * Create a new job instance.
  49. */
  50. public function __construct($sid, $hid)
  51. {
  52. $this->sid = $sid;
  53. $this->hid = $hid;
  54. }
  55. /**
  56. * Execute the job.
  57. */
  58. public function handle(): void
  59. {
  60. $sid = $this->sid;
  61. $hid = $this->hid;
  62. $status = StatusService::get($sid, false);
  63. if(!$status) {
  64. return;
  65. }
  66. if(!in_array($status['pf_type'], ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
  67. return;
  68. }
  69. $ids = HashtagFollowService::getPidByHid($hid);
  70. if(!$ids || !count($ids)) {
  71. return;
  72. }
  73. foreach($ids as $id) {
  74. HomeTimelineService::rem($id, $sid);
  75. }
  76. }
  77. }