<commit_before><?php

namespace Oro\Bundle\ImapBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

use Oro\Bundle\EmailBundle\Entity\EmailFolder;
use Oro\Bundle\EmailBundle\Entity\EmailOrigin;
use Oro\Bundle\ImapBundle\Entity\ImapEmail;

class ImapEmailRepository extends EntityRepository
{
    /**
     * @param EmailFolder $folder
     * @param int[]       $uids
     *
     * @return QueryBuilder
     */
    public function getEmailsByUidsQueryBuilder(EmailFolder $folder, array $uids)
    {
        return $this->createQueryBuilder('imap_email')
            ->innerJoin('imap_email.email', 'email')
            ->innerJoin('email.emailUsers', 'email_users')
            ->innerJoin('email_users.folder', 'folder')
            ->where('folder = :folder AND imap_email.uid IN (:uids)')
            ->setParameter('folder', $folder)
            ->setParameter('uids', $uids);
    }

    /**
     * @param EmailFolder $folder
     * @param int[]       $uids
     *
     * @return int[] Existing UIDs
     */
    public function getExistingUids(EmailFolder $folder, array $uids)
    {
        $rows = $this->getEmailsByUidsQueryBuilder($folder, $uids)
            ->select('imap_email.uid')
            ->getQuery()
            ->getResult();

        $result = [];
        foreach ($rows as $row) {
            $result[] = $row['uid'];<commit_msg>CRM-3975: Fix getting uids of imap emails by email folder and messages<commit_after><?php

namespace Oro\Bundle\ImapBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

use Oro\Bundle\EmailBundle\Entity\EmailFolder;
use Oro\Bundle\EmailBundle\Entity\EmailOrigin;
use Oro\Bundle\ImapBundle\Entity\ImapEmail;

class ImapEmailRepository extends EntityRepository
{
    /**
     * @param EmailFolder $folder
     * @param int[]       $uids
     *
     * @return QueryBuilder
     */
    public function getEmailsByUidsQueryBuilder(EmailFolder $folder, array $uids)
    {
        return $this->createQueryBuilder('imap_email')
            ->innerJoin('imap_email.imapFolder', 'imapFolder')
            ->innerJoin('imapFolder.folder', 'folder')
            ->where('folder = :folder AND imap_email.uid IN (:uids)')
            ->setParameter('folder', $folder)
            ->setParameter('uids', $uids);
    }

    /**
     * @param EmailFolder $folder
     * @param int[]       $uids
     *
     * @return int[] Existing UIDs
     */
    public function getExistingUids(EmailFolder $folder, array $uids)
    {
        $rows = $this->getEmailsByUidsQueryBuilder($folder, $uids)
            ->select('imap_email.uid')
            ->getQuery()
            ->getResult();

        $result = [];
        foreach ($rows as $row) {
            $result[] = $row['uid'];
{'fraction_non_alphanumeric': 0.134194474345174, 'fraction_numerical': 0.0014352350197344816, 'mean_word_length': 2.616083009079118, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6744193', 'n_tokens_mistral': 847, 'n_tokens_neox': 840, 'n_words': 164}