-
Notifications
You must be signed in to change notification settings - Fork 577
cache invalidation for Facilityretreive cache on identifier updation #3501
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from .patient import * # noqa F403 | ||
| from .patient import * # noqa: F403 | ||
| from .patient_identifier import * # noqa: F403 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .cache_invalidation import * # noqa: F403 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from django.core.cache import cache | ||
| from django.db.models.signals import post_save | ||
|
|
||
| from care.emr.models.patient import PatientIdentifierConfig | ||
| from care.emr.resources.base import model_cache_key, model_string | ||
| from care.facility.models import Facility | ||
|
|
||
|
|
||
| def invalidate_facility_cache_on_identifier_change(sender, instance, **kwargs): | ||
| facility_model_string = model_string(Facility) | ||
|
|
||
| if instance.facility_id: | ||
| cache.delete_pattern( | ||
| model_cache_key(facility_model_string, pk=instance.facility.external_id) | ||
| ) | ||
| else: | ||
| cache.delete_pattern(model_cache_key(facility_model_string)) | ||
|
Comment on lines
+9
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find model_cache_key function definition
rg -n "def model_cache_key" --type=pyRepository: ohcnetwork/care Length of output: 110 🏁 Script executed: # Find model_string function definition
rg -n "def model_string" --type=pyRepository: ohcnetwork/care Length of output: 135 🏁 Script executed: # Find Facility model definition and external_id field
rg -n "class Facility" care/facility/models/facility.py -A 30 | head -50Repository: ohcnetwork/care Length of output: 2300 🏁 Script executed: # Search for external_id field on Facility model
rg -n "external_id\s*=" care/facility/models/facility.py -B 2 -A 2Repository: ohcnetwork/care Length of output: 41 🏁 Script executed: # Look for how cache keys are used elsewhere with Facility
rg -n "model_cache_key.*Facility" --type=py -B 2 -A 2Repository: ohcnetwork/care Length of output: 41 🏁 Script executed: # Check if external_id has null constraints
rg -n "external_id" care/facility/models/facility.py | head -20Repository: ohcnetwork/care Length of output: 41 🏁 Script executed: # Read model_cache_key implementation
sed -n '205,230p' care/emr/resources/base.pyRepository: ohcnetwork/care Length of output: 1063 🏁 Script executed: # Read model_string implementation
sed -n '196,210p' care/emr/resources/base.pyRepository: ohcnetwork/care Length of output: 514 🏁 Script executed: # Find BaseModel definition
rg -n "class BaseModel" --type=py care/Repository: ohcnetwork/care Length of output: 118 🏁 Script executed: # Search for external_id more broadly in facility-related files
fd -e py care/facility | xargs rg "external_id" 2>/dev/nullRepository: ohcnetwork/care Length of output: 50747 🏁 Script executed: # Look at the full Facility model
wc -l care/facility/models/facility.pyRepository: ohcnetwork/care Length of output: 95 🏁 Script executed: # Check the base cache invalidation logic
sed -n '196,240p' care/emr/resources/base.pyRepository: ohcnetwork/care Length of output: 1723 🏁 Script executed: # Search for other places where Facility cache is accessed/invalidated
rg "cache.*Facility\|Facility.*cache" care/emr/resources/ -B 2 -A 2 | head -100Repository: ohcnetwork/care Length of output: 41 🏁 Script executed: # Look at the actual signal handler connection for patient_identifier
rg -n "invalidate_facility_cache_on_identifier_change" --type=py -B 5 -A 10Repository: ohcnetwork/care Length of output: 2051 🏁 Script executed: # Look for how cache keys are actually generated and used
rg "model_cache_key\(" care/emr/resources/base.py -A 2 -B 2Repository: ohcnetwork/care Length of output: 943 🏁 Script executed: # Check if there are any other examples of facility cache invalidation
rg "invalidate.*facility\|Facility.*cache" care/emr/signals/ -iRepository: ohcnetwork/care Length of output: 41 🏁 Script executed: # Check what PatientIdentifierConfig is and how it relates to Facility
rg "class PatientIdentifierConfig" --type=py -A 10Repository: ohcnetwork/care Length of output: 5702 🏁 Script executed: # See if there are similar cache invalidation patterns elsewhere
rg "post_save.*connect" care/emr/signals/ -B 5 -A 5 | head -80Repository: ohcnetwork/care Length of output: 910 Cache invalidation should follow the established pattern: invalidate by both The concern about cache.delete_pattern(model_cache_key(sender_model_string, pk=instance.id))
if external_id := getattr(instance, "external_id", None):
cache.delete_pattern(model_cache_key(sender_model_string, pk=external_id))Align with this pattern to avoid stale cache entries keyed by 🧰 Tools🪛 Ruff (0.14.14)[warning] 9-9: Unused function argument: (ARG001) [warning] 9-9: Unused function argument: (ARG001) 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| post_save.connect( | ||
| invalidate_facility_cache_on_identifier_change, | ||
| sender=PatientIdentifierConfig, | ||
| dispatch_uid="invalidate_facility_cache_on_identifier_config_save", | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
fd "cache_invalidation.py" --type fRepository: ohcnetwork/care
Length of output: 161
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 1028
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 83
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 965
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 1210
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 1473
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 1190
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 664
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 550
Silence Ruff's unused argument warnings for signal handler parameters.
Line 9 defines
senderand**kwargsbut never uses them; Ruff's ARG rule will flag this. Rename to_senderand**_kwargs(the Django signal handler signature requires these, even when unused).🔧 Lint-friendly fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.14.14)
[warning] 9-9: Unused function argument:
sender(ARG001)
[warning] 9-9: Unused function argument:
kwargs(ARG001)
🤖 Prompt for AI Agents