Skip to content

Commit

Permalink
Merge branch 'mk/3336-expire-cache-on-dd-delete' into autostaging
Browse files Browse the repository at this point in the history
  • Loading branch information
mkangia committed Feb 21, 2024
2 parents 2fe2b42 + 2408dd8 commit a7e3017
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions corehq/apps/app_manager/app_schemas/case_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,10 @@ def _get_usercase_default_properties(domain):

fields_def = CustomDataFieldsDefinition.get_or_create(domain, CUSTOM_USER_DATA_FIELD_TYPE)
return [f.slug for f in fields_def.get_fields()]


def expire_case_properties_caches(domain):
all_case_properties_by_domain.clear(domain, True, True)
all_case_properties_by_domain.clear(domain, True, False)
all_case_properties_by_domain.clear(domain, False, True)
all_case_properties_by_domain.clear(domain, False, False)
7 changes: 2 additions & 5 deletions corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
remote_app,
)
from corehq.apps.app_manager.app_schemas.case_properties import (
all_case_properties_by_domain,
expire_case_properties_caches,
get_all_case_properties,
get_usercase_properties,
)
Expand Down Expand Up @@ -4538,10 +4538,7 @@ def save(self, response_json=None, increment_version=None, **params):
# expire cache unless new application
self.global_app_config.clear_version_caches()
get_all_case_properties.clear(self)
all_case_properties_by_domain.clear(self.domain, True, True)
all_case_properties_by_domain.clear(self.domain, True, False)
all_case_properties_by_domain.clear(self.domain, False, True)
all_case_properties_by_domain.clear(self.domain, False, False)
expire_case_properties_caches(self.domain)
get_usercase_properties.clear(self)
get_app_languages.clear(self.domain)
get_apps_in_domain.clear(self.domain, True)
Expand Down
5 changes: 5 additions & 0 deletions corehq/apps/data_dictionary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from dimagi.utils.couch import CriticalSection
from dimagi.utils.parsing import ISO_DATE_FORMAT

from corehq import privileges
from corehq.apps.accounting.utils import domain_has_privilege
from corehq.apps.app_manager.app_schemas.case_properties import expire_case_properties_caches
from corehq.apps.case_importer import exceptions


Expand Down Expand Up @@ -147,6 +150,8 @@ def clear_caches(cls, domain, case_type):
)
get_data_dict_props_by_case_type.clear(domain)
get_gps_properties.clear(domain, case_type)
if domain_has_privilege(domain, privileges.DATA_DICTIONARY):
expire_case_properties_caches(domain)

def save(self, *args, **kwargs):
self.clear_caches(self.case_type.domain, self.case_type.name)
Expand Down

0 comments on commit a7e3017

Please sign in to comment.