<commit_before><?php
/**
 * This file is part of the Bruery Platform.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * Copyright (c) 2016. For the full copyright and license information, please view the LICENSE  file that was distributed with this source code.
 */

namespace Bruery\ClassificationBundle\Entity;

use Sonata\ClassificationBundle\Entity\ContextManager as BaseContextManager;

class ContextManager extends BaseContextManager
{
    protected $slugify;

    /**
     * @return mixed
     */
    public function getSlugify()
    {
        return $this->slugify;
    }

    /**
     * @param mixed $slugify
     */
    public function setSlugify($slugify)
    {
        $this->slugify = $slugify;
    }

    /**
     * @param array $contexts
     * @param bool $enabled
     *
     * @return Array
     */
    public function getDefunctContext(array $contexts, $enabled = true)
    {
        $query = $this->getObjectManager()->createQueryBuilder()
            ->select('c')
            ->from($this->getClass(), 'c')
            ->where('c.id NOT IN (:context)')
            ->andWhere('c.enabled = :enabled')
            ->setParameter('context', $contexts)
            ->setParameter('enabled', $enabled)
            ->getQuery()
            ->useResultCache(true, 3600);

        $defunctContexts = $query->getResult();

        return $defunctContexts;
    }

    public function generateDefaultContext($code='default', $name = null, $enabled = true)
    {
        if (!$name) {
            $code = $this->getSlugify()->slugify($code);
            $name = ucwords(str_replace('-', ' ', $code));
        }
        $id = $this->getSlugify()->slugify($name);
        $context = $this->create();
        $context->setEnabled($enabled);
        $context->setId($code);
        $context->setName(substr($name, 0, 255));
        $this->save($context);
        return $context;
    }
}<commit_msg>Added useQueryCache for queries.<commit_after><?php
/**
 * This file is part of the Bruery Platform.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * Copyright (c) 2016. For the full copyright and license information, please view the LICENSE  file that was distributed with this source code.
 */

namespace Bruery\ClassificationBundle\Entity;

use Sonata\ClassificationBundle\Entity\ContextManager as BaseContextManager;

class ContextManager extends BaseContextManager
{
    protected $slugify;

    /**
     * @return mixed
     */
    public function getSlugify()
    {
        return $this->slugify;
    }

    /**
     * @param mixed $slugify
     */
    public function setSlugify($slugify)
    {
        $this->slugify = $slugify;
    }

    /**
     * @param array $contexts
     * @param bool $enabled
     *
     * @return Array
     */
    public function getDefunctContext(array $contexts, $enabled = true)
    {
        $query = $this->getObjectManager()->createQueryBuilder()
            ->select('c')
            ->from($this->getClass(), 'c')
            ->where('c.id NOT IN (:context)')
            ->andWhere('c.enabled = :enabled')
            ->setParameter('context', $contexts)
            ->setParameter('enabled', $enabled)
            ->getQuery()
            ->useQueryCache(true, 3600)
            ->useResultCache(true, 3600);

        $defunctContexts = $query->getResult();

        return $defunctContexts;
    }

    public function generateDefaultContext($code='default', $name = null, $enabled = true)
    {
        if (!$name) {
            $code = $this->getSlugify()->slugify($code);
            $name = ucwords(str_replace('-', ' ', $code));
        }
        $id = $this->getSlugify()->slugify($name);
        $context = $this->create();
        $context->setEnabled($enabled);
        $context->setId($code);
        $context->setName(substr($name, 0, 255));
        $this->save($context);
        return $context;
    }
}
{'fraction_non_alphanumeric': 0.1519443729075457, 'fraction_numerical': 0.0072109193922225085, 'mean_word_length': 2.3482758620689657, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 62, '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': '4937487', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1142, 'n_words': 257}