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

(dev/core#635) Reduce unnecessary SQL writes #13394

Merged
merged 2 commits into from
Jan 8, 2019

Conversation

totten
Copy link
Member

@totten totten commented Jan 4, 2019

Overview

To meaningfully use replay-on-write strategy, one should avoid unnecessary SQL writes.

Before

  • CRM_Contact_Selector stores the result-count in the SQL-backed cache (civicrm_cache) regardless of the configuration.
  • CRM_Contact_Selector and CRM_Campaign_Selector_Search add a cache-record to civicrm_cache to facilitate cleanup of civicrm_prevnext_cache.

After

  • CRM_Contact_Selector stores the result-count in the long cache, which could be Redis/Memcache or SQL (depending on the local configuration).
  • CRM_Contact_Selector and CRM_Campaign_Selector_Search add the record... but only if civicrm_prevnext_cache is actually being used.

totten added 2 commits January 3, 2019 19:20
The selector was set to specifically store the size of the result set in the
SQL-based cache.  For epic:ro-db, we should be able to store these in a
non-SQL location.  The `long` cache suffices.
This line of code creates an extra record to facilitate clearing the
SQL-based prevnext cache.  However, with Redis-based prevnext cache, it's
not needed because the Redis implementation simply uses a TTL -- and (on
Redis deployments) this lines to gratuitous SQL writes.
@civibot civibot bot added the master label Jan 4, 2019
@civibot
Copy link

civibot bot commented Jan 4, 2019

(Standard links)

CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
if (Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) {
// SQL-backed prevnext cache uses an extra record for pruning the cache.
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To see that this is only relevant to SQL-based prevnext cache, one can follow these steps:

  1. Grep for "CiviCRM Search PrevNextCache"
  2. Determine the only party reading this record is CRM_Core_BAO_PrevNextCache::cleanupCache()
  3. Observe that this is a cleanup function focused on civicrm_cache joined with civicrm_prevnext_cache. Per dev/core#217, the search screens (CRM_Contact_Selector) only puts data into civicrm_prevnext_cache if we're using the SQL-based driver.

@colemanw
Copy link
Member

colemanw commented Jan 8, 2019

Agreed.

@colemanw colemanw merged commit 9360fd2 into civicrm:master Jan 8, 2019
@totten totten deleted the master-srchcache branch January 8, 2019 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants