<commit_before><?php
namespace SimplyTestable\ApiBundle\Repository;

use Doctrine\ORM\EntityRepository;

class TaskOutputRepository extends EntityRepository
{
    public function findUnusedIds($limit) {
        $queryBuilder = $this->createQueryBuilder('TaskOutput');
        $queryBuilder->select('TaskOutput.id');        
        
        $queryBuilder->leftJoin('SimplyTestable\ApiBundle\Entity\Task\Task', 'Task', 'WITH', 'TaskOutput.id = Task.output');
        $queryBuilder->where('Task.output IS NULL');
        $queryBuilder->orderBy('TaskOutput.id', 'ASC');
        
        if (is_int($limit) && $limit > 0) {
            $queryBuilder->setMaxResults($limit);
        }
        
        $result = $queryBuilder->getQuery()->getResult();
        
        $ids = array();
        
        foreach ($result as $idResult) {
            $ids[] = $idResult['id'];
        }
        
        return $ids; 
        
/**
 * 
SELECT DISTINCT TaskOutput.id
FROM  `TaskOutput` <commit_msg>Improve performance of retrieving list of unused taskoutput ids by many orders of amazing magnitude<commit_after><?php
namespace SimplyTestable\ApiBundle\Repository;

use Doctrine\ORM\EntityRepository;

class TaskOutputRepository extends EntityRepository
{
    public function findUnusedIds($limit) {
        $queryBuilder = $this->createQueryBuilder('TaskOutput');
        $queryBuilder->select('DISTINCT TaskOutput.id');        
        
        $queryBuilder->leftJoin('SimplyTestable\ApiBundle\Entity\Task\Task', 'Task', 'WITH', 'TaskOutput.id = Task.output');
        $queryBuilder->where('Task.output IS NULL');
        
        if (is_int($limit) && $limit > 0) {
            $queryBuilder->setMaxResults($limit);
        }
        
        $result = $queryBuilder->getQuery()->getResult();        
        
        return $this->getSingleFieldCollectionFromResult($result, 'id');
        
/**
 * 
SELECT DISTINCT TaskOutput.id
FROM  `TaskOutput` 
{'fraction_non_alphanumeric': 0.13137557959814528, 'fraction_numerical': 0.0010303967027305513, 'mean_word_length': 2.7418111753371868, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6888779', 'n_tokens_mistral': 538, 'n_tokens_neox': 531, 'n_words': 100}