Skip to content

Memory issue - Toolbar collects every query #1607

Description

@Martin-4Spaces

I'm doing some heavy imports with a lot of queries.
After I fixed this issue I encountered another memory issue.
This time it is caused by the debug toolbar in non production environment.
It is collecting every query in an array at CodeIgniter\Debug\Toolbar\Collectors\Database::collect:

/**
 * The static method used during Events to collect
 * data.
 *
 * @param \CodeIgniter\Database\Query $query
 *
 * @internal param $ array \CodeIgniter\Database\Query
 */
public static function collect(Query $query)
{
    static::$queries[] = $query;
}

A simple max on the array size should fix the problem. Ex.

/**
 * The static method used during Events to collect
 * data.
 *
 * @param \CodeIgniter\Database\Query $query
 *
 * @internal param $ array \CodeIgniter\Database\Query
 */
public static function collect(Query $query)
{
    static::$queries[] = $query;

    if(count(static::$queries) >= 100) {
        static::$queries = array_slice(static::$queries, 50);
    }
}

This will cut the array in half every time it hits 100 elements.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions