Breakpoints are being loaded on every page request via ctools_export. The call to load breakpoints is made a number of times throughout the request. This process can be improved by making a single request to the database and storing the breakpoints into memory.

The two attached screenshots show a minor implementation of breakpoints with significant results.

Comments

KeyboardCowboy created an issue. See original summary.

KeyboardCowboy’s picture

StatusFileSize
new1.87 KB

This patch stores the breakpoints into memory on the first request and uses that data to serve subsequent load requests instead of querying the database.

KeyboardCowboy’s picture

Category: Feature request » Task
KeyboardCowboy’s picture

StatusFileSize
new4.8 KB

This patch takes things a step further and utilizes Drupal's caching system to store the breakpoint and group data. This will allow sites running memcache to store the breakpoints data into memcache, thus completely eliminating the breakpoint database requests until the cache is cleared.

  • attiks committed 6511f86 on 7.x-1.x authored by KeyboardCowboy
    Issue #2636672 by KeyboardCowboy: Reduce Number of SQL Calls By Storing...
attiks’s picture

Status: Active » Reviewed & tested by the community

Committed and pushed to dev version, can somebody test it so I can make a release

dave reid’s picture

+++ b/breakpoints.module
@@ -360,15 +363,26 @@ function breakpoints_breakpoint_load($name, $source, $source_type) {
+  $breakpoints = &drupal_static(__FUNCTION__, NULL);

The places that are now calling cache_clear_all() are not calling drupal_static_reset() so this function will contain stale data until the next request.

Overall I feel like this is odd knowing that CTools itself also uses database caching, and rather than storing in yet-another-database-cache, just adding static caching, and loading them all at once from CTools would be the primary improvement.

dave reid’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.53 KB

Yes, we just have to enable 'cache defaults' as per the CTools export documentation.

dave reid’s picture

Hrm, so the caching is for the default exported objects, so it skips invoking the hooks, but still requires one database read on loading either all breakpoints or all groups for reading from the table itself.

dave reid’s picture

StatusFileSize
new6.41 KB

This gets me down to loading from the cache table only for both breakpoints and breakpoint groups. Abstract cache clearing to separate functions for re-use, and takes advantage of the 'load all callback' to help centralize caching.

dave reid’s picture

dave reid’s picture

StatusFileSize
new6.43 KB

Missed that $bin parameter to cache_clear_all() is required if using a specific $cid parameter.

attiks’s picture

Committed to dev

  • attiks committed 3c7ca5f on 7.x-1.x authored by Dave Reid
    Issue #2636672 by Dave Reid, KeyboardCowboy: Reduce Number of SQL Calls...
jelle_s’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.