FeedRemoveDomainPipeline.php 2.5 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 Illuminate\Queue\Middleware\WithoutOverlapping;
  10. use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
  11. use App\Services\StatusService;
  12. use App\Services\HomeTimelineService;
  13. class FeedRemoveDomainPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. protected $pid;
  17. protected $domain;
  18. public $timeout = 900;
  19. public $tries = 3;
  20. public $maxExceptions = 1;
  21. public $failOnTimeout = true;
  22. /**
  23. * The number of seconds after which the job's unique lock will be released.
  24. *
  25. * @var int
  26. */
  27. public $uniqueFor = 3600;
  28. /**
  29. * Get the unique ID for the job.
  30. */
  31. public function uniqueId(): string
  32. {
  33. return 'hts:feed:remove:domain:' . $this->pid . ':d-' . $this->domain;
  34. }
  35. /**
  36. * Get the middleware the job should pass through.
  37. *
  38. * @return array<int, object>
  39. */
  40. public function middleware(): array
  41. {
  42. return [(new WithoutOverlapping("hts:feed:remove:domain:{$this->pid}:d-{$this->domain}"))->shared()->dontRelease()];
  43. }
  44. /**
  45. * Create a new job instance.
  46. */
  47. public function __construct($pid, $domain)
  48. {
  49. $this->pid = $pid;
  50. $this->domain = $domain;
  51. }
  52. /**
  53. * Execute the job.
  54. */
  55. public function handle(): void
  56. {
  57. if(!config('exp.cached_home_timeline')) {
  58. return;
  59. }
  60. if(!$this->pid || !$this->domain) {
  61. return;
  62. }
  63. $domain = strtolower($this->domain);
  64. $pid = $this->pid;
  65. $posts = HomeTimelineService::get($pid, '0', '-1');
  66. foreach($posts as $post) {
  67. $status = StatusService::get($post, false);
  68. if(!$status || !isset($status['url'])) {
  69. HomeTimelineService::rem($pid, $post);
  70. continue;
  71. }
  72. $host = strtolower(parse_url($status['url'], PHP_URL_HOST));
  73. if($host === strtolower(config('pixelfed.domain.app')) || !$host) {
  74. continue;
  75. }
  76. if($host === $domain) {
  77. HomeTimelineService::rem($pid, $status['id']);
  78. }
  79. }
  80. }
  81. }