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

Fixed cache clearing for bulk-accepted suggestions. #2233

Merged

Conversation

caiosba
Copy link
Contributor

@caiosba caiosba commented Feb 24, 2025

Description

Previously, the id was incorrectly used as target_ids. Also, now, all relevant fields are included, not just a subset.

Fixes: CV2-6191.

How to test?

I implemented a unit test that reproduces the issue.

Checklist

  • I have performed a self-review of my code and ensured that it is safe and runnable, that code coverage has not decreased, and that there are no new Code Climate issues. I have also followed Meedan's internal coding guidelines.

Previously, the id was incorrectly used as target_ids. Now, all relevant fields are included, not just a subset.

Fixes: CV2-6191.
@@ -20,7 +20,6 @@ def bulk_update(ids, updates, team)
end
relationships = Relationship.where(id: ids, source_id: source_id)
relationships.update_all(update_columns)
delete_cached_field(pm_source.id, ids)
Copy link
Contributor

Choose a reason for hiding this comment

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

@caiosba: before we were passing the relationship ids instead of the target project medias id, but we want to delete_cached_field for source and target project medias, correct?

Could we go through this file in our 1:1? I have other questions, like: why did you change the delete_cached_field method, and sort of related, why on like 31 we pass pm_source.id instead of source_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's go through it in our 1:1, but I'm going to answer here for documentation as well.

There was a bug: We wanted to clear the cache for all project media IDs (source and targets, a.k.a. parent and children), but by mistake, the relationship IDs were being passed.

There is no difference between source_id and pm.source_id, it was only Sawy's preference :)

I took the opportunity to simplify, improve and refactor some things:

  • Rename the method, since we're clearing multiple cached fields instead of only one
  • Use the built-in method to clear all cached fields instead of manually clearing a hard-coded list of fields, because the previous implementation had knowledge it shouldn't have about how the cached fields work internally (like, the cache key format and which fields are affected by relationship). Also, it would miss it if we added a new field (which happened here - it was missing the media_cluster_origin field, that was added after this implementation

@caiosba caiosba merged commit d95e6b9 into develop Feb 24, 2025
11 checks passed
@caiosba caiosba deleted the fix/CV2-6191-clear-cache-on-bulk-accepting-suggestion branch February 24, 2025 15:01
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.

4 participants