Avoid full cache clear whenever a rules component or reaction rule is edited

Created on 5 February 2014, over 10 years ago
Updated 31 July 2020, about 4 years ago

Updated: Comment #N

Problem/Motivation

Currently RulesPlugin:save() clears the whole cache if the no original entity was found
or if the variables from the original entity don't match with the current ones.
Problem with this approach is that the property original never exists
because it's deleted by EntityAPIController::save().
In our environment with a looooot of rules (that are triggered in the frontend) this causes some serious trouble (stampeding) when rebuilding the whole cache.
Especially since the "cache" rules_event_whitelist is handled as variable: #2042851: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'rules_event_whitelist' for key 'PRIMARY
This would be less of a problem if it would be handled by cache_get() because we use redis and that wouldn't fail this way.
However, I guess the performance problem is already enough annoying to justify a fix ;)

Proposed resolution

Fetch the original entity on our own and make it reusable for the other entity controllers.
This pattern is already implemented in several other locations e.g. RulesEntityController::save().
Question:
Is there a way to make the cache flush even more atomic?
E.g. just removing the current component from the cache data array.
The patch rules-rules-plugin-cache-clearing-fix-flush-specific-component.patch contains a POC to test such an approach. The tests so far show a dramatic performance gain.

Remaining tasks

Reviews needed.

User interface changes

None

API changes

None

Feature request
Status

RTBC

Version

2.0

Component

Rules Core

Created by

🇨🇭Switzerland das-peter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024