<commit_before><?php

/*
 * This file is part of the Denbolan project.
 *
 * Copyright (c) 2015-2016 LIN3S <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace LIN3S\AdminBundle\Repository;

use Doctrine\ORM\EntityManager;
use LIN3S\AdminBundle\Configuration\EntityConfiguration;
use Symfony\Component\HttpFoundation\Request;

class AdminRepository
{
    public function findByRequest(Request $request, EntityConfiguration $config)
    {
        $queryBuilder = $config->queryBuilder()->generate($request, $config);

        $postPerPage = $config->listEntitiesPerPage();

        $offset = ($request->get('page', 1) - 1) * $postPerPage;
        $limit = $postPerPage;

        $queryBuilder->setFirstResult($offset);
        $queryBuilder->setMaxResults($limit);

        return $queryBuilder->getQuery()->getResult();
    }

    public function countAll(Request $request, EntityConfiguration $config)
    {
        $queryBuilder = $config->queryBuilder()->generate($request, $config);
        $queryBuilder->select($queryBuilder->expr()->count('a.id'));

        return count($queryBuilder->getQuery()->getScalarResult());
    }


}
<commit_msg>Forced count of query to whole entity (is not the best choice for performance but works well in generic solutions)<commit_after><?php

/*
 * This file is part of the Denbolan project.
 *
 * Copyright (c) 2015-2016 LIN3S <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace LIN3S\AdminBundle\Repository;

use Doctrine\ORM\EntityManager;
use LIN3S\AdminBundle\Configuration\EntityConfiguration;
use Symfony\Component\HttpFoundation\Request;

class AdminRepository
{
    public function findByRequest(Request $request, EntityConfiguration $config)
    {
        $queryBuilder = $config->queryBuilder()->generate($request, $config);

        $postPerPage = $config->listEntitiesPerPage();

        $offset = ($request->get('page', 1) - 1) * $postPerPage;
        $limit = $postPerPage;

        $queryBuilder->setFirstResult($offset);
        $queryBuilder->setMaxResults($limit);

        return $queryBuilder->getQuery()->getResult();
    }

    public function countAll(Request $request, EntityConfiguration $config)
    {
        $queryBuilder = $config->queryBuilder()->generate($request, $config);
        $queryBuilder->select($queryBuilder->expr()->count('a'));

        return count($queryBuilder->getQuery()->getScalarResult());
    }


}

{'fraction_non_alphanumeric': 0.1290446841294299, 'fraction_numerical': 0.010015408320493066, 'mean_word_length': 3.9466666666666668, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, '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': '6738490', 'n_tokens_mistral': 727, 'n_tokens_neox': 691, 'n_words': 173}