<commit_before><?php
declare(strict_types = 1);

namespace Externals\Domain\Thread;

use Doctrine\DBAL\Connection;
use Externals\Domain\NotFound;

/**
 * @author <NAME> <<EMAIL>>
 */
class DbThreadRepository implements ThreadRepository
{
    /**
     * @var Connection
     */
    private $db;

    public function __construct(Connection $db)
    {
        $this->db = $db;
    }

    public function findBySubject(string $subject)
    {
        $threadId = $this->db->fetchColumn('SELECT id FROM threads WHERE subject = ?', [$subject]);

        return $threadId ? (int) $threadId : null;
    }

    public function getSubject(int $id) : string
    {
        $subject = $this->db->fetchColumn('SELECT subject FROM threads WHERE id = ?', [$id]);

        if (!$subject) {
            throw new NotFound('No thread found for ID ' . $id);
        }

        return $subject;
    }

    public function create(string $subject) : int
    {
        $this->db->insert('threads', [
            'subject' => $subject,
        ]);

        return (int) $this->db->lastInsertId();
    }

    public function findLatest() : array
    {
        $query = 'SELECT threads.id, threads.subject, COUNT(emails.id), MAX(emails.date) as lastUpdate
            FROM threads
            LEFT JOIN emails ON threads.id = emails.threadId
            GROUP BY threads.id
            ORDER BY lastUpdate DESC
            LIMIT 10';
        return $this->db->fetchAll($query);
    }
}<commit_msg>Show more threads<commit_after><?php
declare(strict_types = 1);

namespace Externals\Domain\Thread;

use Doctrine\DBAL\Connection;
use Externals\Domain\NotFound;

/**
 * @author <NAME> <<EMAIL>>
 */
class DbThreadRepository implements ThreadRepository
{
    /**
     * @var Connection
     */
    private $db;

    public function __construct(Connection $db)
    {
        $this->db = $db;
    }

    public function findBySubject(string $subject)
    {
        $threadId = $this->db->fetchColumn('SELECT id FROM threads WHERE subject = ?', [$subject]);

        return $threadId ? (int) $threadId : null;
    }

    public function getSubject(int $id) : string
    {
        $subject = $this->db->fetchColumn('SELECT subject FROM threads WHERE id = ?', [$id]);

        if (!$subject) {
            throw new NotFound('No thread found for ID ' . $id);
        }

        return $subject;
    }

    public function create(string $subject) : int
    {
        $this->db->insert('threads', [
            'subject' => $subject,
        ]);

        return (int) $this->db->lastInsertId();
    }

    public function findLatest() : array
    {
        $query = 'SELECT threads.id, threads.subject, COUNT(emails.id), MAX(emails.date) as lastUpdate
            FROM threads
            LEFT JOIN emails ON threads.id = emails.threadId
            GROUP BY threads.id
            ORDER BY lastUpdate DESC
            LIMIT 30';
        return $this->db->fetchAll($query);
    }
}
{'fraction_non_alphanumeric': 0.12984364377974167, 'fraction_numerical': 0.0020394289598912306, 'mean_word_length': 2.259136212624585, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, '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': '6188962', 'n_tokens_mistral': 879, 'n_tokens_neox': 841, 'n_words': 222}