To investigate something else I added a DB tracing feature to optionally output SQL queries and their callers to a log file (commit 1). During that investigation I discovered that we're doing the same query against quiz_passes table and current_tallies multiple times in a page load. I traced that back to the Activity->user_access() call.
This PR removes a redundant call in gradual.inc (this is the second time we load that object in the function -- see line 335) and adds a small cache within Activity->user_access() for the user score. The cache removes 20 DB queries on each of the round pages and Activity Hub. The queries are fast but add unnecessary load to the DB for data we literally just asked for microseconds before.
To investigate something else I added a DB tracing feature to optionally output SQL queries and their callers to a log file (commit 1). During that investigation I discovered that we're doing the same query against
quiz_passes
table andcurrent_tallies
multiple times in a page load. I traced that back to theActivity->user_access()
call.This PR removes a redundant call in
gradual.inc
(this is the second time we load that object in the function -- see line 335) and adds a small cache withinActivity->user_access()
for the user score. The cache removes 20 DB queries on each of the round pages and Activity Hub. The queries are fast but add unnecessary load to the DB for data we literally just asked for microseconds before.Sandbox: https://www.pgdp.org/~cpeel/c.branch/reduce-db-query-hits/