Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

function qa_db_query_execute($query) causes "memory size bytes exhausted"

+2 votes
78 views
asked Jun 11 in Q2A Core by q2apro

Issue: https://github.com/NoahY/q2a-badges/issues/49

qa-db.php line 196/197: 

for ($attempt = 0; $attempt < 100; $attempt++) {
            $result = $db->query($query);

Any hack to overcome the memory issue? Reducing the $attempt to a lower number (I tried 50) did not work.

Q2A version: 1.7
commented Jun 13 by Scott
What is the query that's being executed? I don't think it's anything to do with that loop in qa-db.php (it should only run once anyway). Possibly the SQL query is trying to fetch too much data at once.
commented Jun 13 by q2apro
"Possibly the SQL query is trying to fetch too much data at once." - I think so too. I still need to find time to dig into the source code of the badge plugin.

1 Answer

+3 votes
answered Jun 13 by q2apro
Problem was in qa-badge-admin.php, line 546:

            $temp = qa_db_query_sub(
                'SELECT * FROM ^posts'
            );

which obviously also selected the posts' content and led to the memory explosion :)

Just replace it by:

            // get post data from table posts
            $temp = qa_db_query_sub(
                'SELECT postid, type, userid, netvotes, parentid, created, views FROM ^posts'
            );

Then it works.
commented Jun 14 by ProThoughts
nice! this will help someone.
...