Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory issue - Toolbar collects every query #1607

Closed
Martin-4Spaces opened this issue Dec 12, 2018 · 6 comments
Closed

Memory issue - Toolbar collects every query #1607

Martin-4Spaces opened this issue Dec 12, 2018 · 6 comments
Assignees

Comments

@Martin-4Spaces
Copy link

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.

@lonnieezell
Copy link
Member

that's possible, though I've seen valid sites running upwards of 200 queries (think joomla type sites) so this would cause issues trying to track things down there.

A solution for your current situation might be to turn off the query collection for the toolbar. You can do this by commenting out the DatabaseCollector in application/Config/Toolbar. Then no queries will be collected.

@Martin-4Spaces
Copy link
Author

200 queries should not cause any memory issues. 10.000 as in my case is a memory issue :D

I solved my issue by commenting out this line
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
from application/Config/Events.php.
As I did not have a Toolbar Config file. But that might be a prettier solution.

@lonnieezell
Copy link
Member

Yup - 10,000 queries would definitely be an issue lol.

I think adding a maxQueries setting to the Toolbar config would be a good addition here. That's probably how I'll solve this one.

@tpw1314
Copy link
Contributor

tpw1314 commented Dec 16, 2018

Just one question, which might be irrelevant to this issue. But how do I hide the CI4 debugging bar/button ?

@jim-parry
Copy link
Contributor

@tpw https://forum.codeigniter.com/thread-72292.html
And yes, your question is off-topic and should have been addressed on the forum

@tpw1314
Copy link
Contributor

tpw1314 commented Dec 16, 2018

Thanks for reminding.

@lonnieezell lonnieezell self-assigned this Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants