DistributedProofreaders / dproofreaders

Distributed Proofreaders is a web application intended to ease the process of converting public domain books into e-texts.
https://www.pgdp.net
GNU General Public License v2.0
46 stars 28 forks source link

Reduce the overhead of Activity->user_access() calls #1202

Closed cpeel closed 1 month ago

cpeel commented 1 month ago

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.

Sandbox: https://www.pgdp.org/~cpeel/c.branch/reduce-db-query-hits/