Skip to content

Commit

Permalink
Provide a configurable limit on the number of queries recorded for th…
Browse files Browse the repository at this point in the history
…e toolbar. Fixes #1607
  • Loading branch information
lonnieezell committed Dec 17, 2018
1 parent 614216d commit 24ded3a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
39 changes: 38 additions & 1 deletion app/Config/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@ class Toolbar extends BaseConfig
\CodeIgniter\Debug\Toolbar\Collectors\Routes::class,
\CodeIgniter\Debug\Toolbar\Collectors\Events::class,
];

/*
|--------------------------------------------------------------------------
| Max History
|--------------------------------------------------------------------------
| The Toolbar allows you to view recent requests that have been made to
| the application while the toolbar is active. This allows you to quickly
| view and compare multiple requests.
|
| $maxHistory sets a limit on the number of past requests that are stored,
| helping to conserve file space used to store them. You can set it to
| 0 (zero) to not have any history stored, or -1 for unlimited history.
|
*/
public $maxHistory = 20;
public $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/';

/*
|--------------------------------------------------------------------------
| Toolbar Views Path
|--------------------------------------------------------------------------
| The full path to the the views that are used by the toolbar.
| MUST have a trailing slash.
|
*/
public $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/';

/*
|--------------------------------------------------------------------------
| Max Queries
|--------------------------------------------------------------------------
| If the Database Collector is enabled, it will log every query that the
| the system generates so they can be displayed on the toolbar's timeline
| and in the query log. This can lead to memory issues in some instances
| with hundreds of queries.
|
| $maxQueries defines the maximum amount of queries that will be stored.
|
*/
public $maxQueries = 100;
}
10 changes: 9 additions & 1 deletion system/Debug/Toolbar/Collectors/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ public function __construct()
*/
public static function collect(Query $query)
{
static::$queries[] = $query;
$config = config('Toolbar');

// Provide default in case it's not set
$max = $config->maxQueries ?: 100;

if (count(static::$queries) < $max)
{
static::$queries[] = $query;
}
}

//--------------------------------------------------------------------
Expand Down

0 comments on commit 24ded3a

Please sign in to comment.