<commit_before><?php
namespace Josegonzalez\Version\Model\Behavior\Version;

use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use LogicException;

trait VersionTrait
{
    /**
     * Retrieves a specified version for the current entity
     *
     * @param int $versionId The version number to retrieve
     * @param bool $reset If true, will re-retrieve the related version collection
     * @return \Cake\ORM\Entity
     */
    public function version($versionId, $reset = false)
    {
        $versions = $this->versions($reset);
        if (empty($versions[$versionId])) {
            return null;
        }

        return $versions[$versionId];
    }

    /**
     * Retrieves the related versions for the current entity
     *
     * @param bool $reset If true, will re-retrieve the related version collection
     * @return \Cake\Collection\Collection
     */
    public function versions($reset = false)
    {
        if ($reset === false && $this->has('_versions')) {
            return $this->get('_versions');
        }

        $conditions = ['primaryKey' => $this->id];

        $table = TableRegistry::get($this->source());
        $entities = $table->find('versions', $conditions)
                        ->bufferResults(false)
                        ->all();

        if (empty($entities)) {
            return [];
        }

        $entity = $entities->first();
        $this->set('_versions', $entity->get('_versions'));
        return $this->get('_versions');
    }
}<commit_msg>Do not use bufferResults(false)<commit_after><?php
namespace Josegonzalez\Version\Model\Behavior\Version;

use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use LogicException;

trait VersionTrait
{
    /**
     * Retrieves a specified version for the current entity
     *
     * @param int $versionId The version number to retrieve
     * @param bool $reset If true, will re-retrieve the related version collection
     * @return \Cake\ORM\Entity
     */
    public function version($versionId, $reset = false)
    {
        $versions = $this->versions($reset);
        if (empty($versions[$versionId])) {
            return null;
        }

        return $versions[$versionId];
    }

    /**
     * Retrieves the related versions for the current entity
     *
     * @param bool $reset If true, will re-retrieve the related version collection
     * @return \Cake\Collection\Collection
     */
    public function versions($reset = false)
    {
        if ($reset === false && $this->has('_versions')) {
            return $this->get('_versions');
        }

        $conditions = ['primaryKey' => $this->id];

        $table = TableRegistry::get($this->source());
        $entities = $table->find('versions', $conditions)
                        ->all();

        if (empty($entities)) {
            return [];
        }

        $entity = $entities->first();
        $this->set('_versions', $entity->get('_versions'));
        return $this->get('_versions');
    }
}
{'fraction_non_alphanumeric': 0.13790783720147998, 'fraction_numerical': 0.0, 'mean_word_length': 2.3044444444444445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '7310134', 'n_tokens_mistral': 821, 'n_tokens_neox': 805, 'n_words': 208}