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

Optimize checkForCacheUpdate to avoid deleting the same cache key multiple times #512

Open
wants to merge 1 commit into
base: hotfix
Choose a base branch
from

Conversation

LoLei
Copy link

@LoLei LoLei commented Jul 18, 2024

Description

In some installations, the same cache key may be multiple times in the cache_rebuild table. Therefore, the same DELETE statement will be executed multiple times, even though it would only be necessary to be executed once, to delete that key from the table. (E.g. DELETE FROM cache_rebuild WHERE cache_key='app-metadata-theme-images'). This change optimizes the loop that iterates over the keys to be deleted, and keeps track of those keys already deleted, to skip any additional superfluous deletions.

Motivation and Context

In our installation, the app-metadata-theme-images cache key was over 200k times in the cache_rebuild table. Therefore, the DELETE FROM cache_rebuild WHERE cache_key='app-metadata-theme-images' was also executed that many times, on the first login of the day, in the appMetaData GraphQL request.

How To Test This

Duplicate the same cache key multiple times in the cache_rebuild table. checkForCacheUpdate should now only call the corresponding deletion once, instead of multiple times. (Set $sugar_config['logger']['level'] = 'info'; to see executed queries in the SuiteCRM log.)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

…tiple times

In some installations, the same cache key may be multiple times in the `cache_rebuild` table. Therefore, the same `DELETE` statement will be executed multiple times, even though it would only be necessary to be executed once, to delete that key from the table. (E.g. `DELETE FROM cache_rebuild WHERE cache_key='app-metadata-theme-images'`). This change optimizes the loop that iterates over the keys to be deleted, and keeps track of those keys already deleted, to skip any additional superfluous deletions.
@SuiteBot
Copy link

SuiteBot commented Jul 18, 2024

CLA assistant check
All committers have signed the CLA.

@chris001
Copy link
Contributor

Should that cache_key be made part of the primary key, so that a record containing it can only occur once, and not need any application code to enforce that the record be unique, and that the deletion of the cache key can then only occur once.

@LoLei
Copy link
Author

LoLei commented Jul 23, 2024

@chris001 Not sure I fully understand your comment. Is this something I can adapt in my PR, or are you thinking in a more theoretical / broader sense?

@chris001
Copy link
Contributor

Broader sense. If the cache_key were part of the primary key, this would not be an issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants