From 69fdad8f4eb2d45810f12f20a1bf94d927169aed Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Thu, 5 Jun 2025 16:28:35 +0200 Subject: [PATCH] Do not get duplicates when finlling with non posted reels --- app/Browser/Jobs/InstagramRepost/InstagramRepostJob.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Browser/Jobs/InstagramRepost/InstagramRepostJob.php b/app/Browser/Jobs/InstagramRepost/InstagramRepostJob.php index 76afda6..a15fcd9 100644 --- a/app/Browser/Jobs/InstagramRepost/InstagramRepostJob.php +++ b/app/Browser/Jobs/InstagramRepost/InstagramRepostJob.php @@ -127,8 +127,13 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces // Add unreposted reels to the job run if not enough reels were downloaded if (count($toDownloadReels) < self::MAX_REPOSTS_PER_JOB) { + $toDownloadReelsIds = array_map(function ($reel) { + return $reel->reel_id; + }, $toDownloadReels); + $unrepostedReels = InstagramRepost::where("reposted", false) ->where("repost_tries", "<", self::MAX_REPOST_TRIES) // Limit to 3 tries + ->whereNotIn("reel_id", $toDownloadReelsIds) // Avoid already downloaded reels ->whereIn("account_id", InstagramAccount::whereIn("username", $accounts)->pluck("id")) ->take(self::MAX_REPOSTS_PER_JOB - count($toDownloadReels)) ->get();