Skip to content

Commit

Permalink
Use feature flag to read from DomainMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nospame committed Dec 13, 2024
1 parent a73ae0e commit 3425359
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions corehq/apps/api/domain_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from corehq.apps.api.resources import CouchResourceMixin, HqBaseResource
from corehq.apps.api.resources.meta import AdminResourceMeta
from corehq.apps.api.serializers import XFormInstanceSerializer
from corehq.apps.data_analytics.models import GIRRow, MALTRow
from corehq.apps.data_analytics.models import DomainMetrics, GIRRow, MALTRow
from corehq.apps.domain.models import Domain, DomainAuditRecordEntry
from corehq.apps.es.domains import DomainES

Expand Down Expand Up @@ -55,16 +55,25 @@ def dehydrate_billing_properties(self, bundle):
}

def dehydrate_calculated_properties(self, bundle):
from corehq.toggles import CALCULATED_PROPERTIES_FROM_DOMAIN_METRICS
calc_prop_prefix = 'cp_'
domain_obj = _get_domain(bundle)
try:
base_properties = self._get_base_properties_from_elasticsearch(domain_obj.name, calc_prop_prefix)
if CALCULATED_PROPERTIES_FROM_DOMAIN_METRICS.enabled(domain_obj.name):
base_properties = self._get_base_properties_from_domain_metrics(domain_obj.name)
else:
base_properties = self._get_base_properties_from_elasticsearch(domain_obj.name, calc_prop_prefix)
properties = self._add_extra_calculated_properties(base_properties, domain_obj.name, calc_prop_prefix)
except IndexError:
except (DomainMetrics.DoesNotExist, IndexError):
logging.exception('Problem getting calculated properties for {}'.format(domain_obj.name))
return {}
return properties

@staticmethod
def _get_base_properties_from_domain_metrics(domain):
domain_metrics = DomainMetrics.objects.get(domain=domain)
return domain_metrics.to_calculated_properties()

@staticmethod
def _get_base_properties_from_elasticsearch(domain, calc_prop_prefix):
es_data = (DomainES()
Expand Down

0 comments on commit 3425359

Please sign in to comment.