<commit_before><?php

use DebugBar\DataCollector\AssetProvider;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use DebugBar\DataCollector\TimeDataCollector;

/**
 * Collects data about SQL statements executed through the DatabaseProxy
 */
class DebugBarDatabaseCollector extends DataCollector implements Renderable, AssetProvider
{
    /**
     * @var TimeDataCollector
     */
    protected $timeCollector;

    /**
     * @var SS_Database
     */
    protected $db;

    /**
     * @param SS_Database $db
     * @param TimeDataCollector $timeCollector
     */
    public function __construct(SS_Database $db, TimeDataCollector $timeCollector = null)
    {
        $this->db            = $db;
        $this->timeCollector = $timeCollector;
    }

    /**
     * @return array
     */
    public function collect()
    {
        $data = $this->collectData($this->timeCollector);

        // Check for excessive number of queries
        $dbQueryWarningLevel = DebugBar::config()->warn_query_limit;
        if ($dbQueryWarningLevel && $data['nb_statements'] > $dbQueryWarningLevel) {
            DebugBar::getDebugBar()
                ->getCollector('messages')
                ->addMessage(
                    'Your page is running a high number of database queries. You could reduce this by implementing '
                    . 'caching. <a href="https://docs.silverstripe.org/en/developer_guides/performance/"'
                    . ' target="_blank">More information.</a>',
                    'warning'
                );
        }

        return $data;
    }

    /**
     * Explode comma separated elements not within parenthesis or quotes
     *
     * @param string $str
     * @return array
     */
    protected static function explodeFields($str)
    {
        return preg_split("/(?![^(]*\)),/", $str);
    }

    /**
     * Collects data
     *
     * @param TimeDataCollector $timeCollector
     * @return array
     */
    protected function collectData(TimeDataCollector $timeCollector = null)
    {
        $stmts = array();<commit_msg>NEW Improve message for large numbers of DB queries to include the threshold<commit_after><?php

use DebugBar\DataCollector\AssetProvider;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use DebugBar\DataCollector\TimeDataCollector;

/**
 * Collects data about SQL statements executed through the DatabaseProxy
 */
class DebugBarDatabaseCollector extends DataCollector implements Renderable, AssetProvider
{
    /**
     * @var TimeDataCollector
     */
    protected $timeCollector;

    /**
     * @var SS_Database
     */
    protected $db;

    /**
     * @param SS_Database $db
     * @param TimeDataCollector $timeCollector
     */
    public function __construct(SS_Database $db, TimeDataCollector $timeCollector = null)
    {
        $this->db            = $db;
        $this->timeCollector = $timeCollector;
    }

    /**
     * @return array
     */
    public function collect()
    {
        $data = $this->collectData($this->timeCollector);

        // Check for excessive number of queries
        $dbQueryWarningLevel = DebugBar::config()->warn_query_limit;
        if ($dbQueryWarningLevel && $data['nb_statements'] > $dbQueryWarningLevel) {
            DebugBar::getDebugBar()
                ->getCollector('messages')
                ->addMessage(
                    'This page ran more than ' . $dbQueryWarningLevel . ' database queries. You could reduce this by '
                    . 'implementing caching. For more information, <a href="https://docs.silverstripe.org/en/'
                    . 'developer_guides/performance/" target="_blank">click here.</a>',
                    'warning'
                );
        }

        return $data;
    }

    /**
     * Explode comma separated elements not within parenthesis or quotes
     *
     * @param string $str
     * @return array
     */
    protected static function explodeFields($str)
    {
        return preg_split("/(?![^(]*\)),/", $str);
    }

    /**
     * Collects data
     *
     * @param TimeDataCollector $timeCollector
     * @return array
     */
    protected function collectData(TimeDataCollector $timeCollector = null)
    {
        $stmts = array();
{'fraction_non_alphanumeric': 0.10996724379971923, 'fraction_numerical': 0.0, 'mean_word_length': 2.268348623853211, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '4103603', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1150, 'n_words': 275}