FeedRemoveDomainPipeline.php 2.6 KB

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