Do not get duplicates when finlling with non posted reels

This commit is contained in:
2025-06-05 16:28:35 +02:00
parent 982f4ca7a7
commit 69fdad8f4e

View File

@ -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();