Skip to content

Commit

Permalink
Merge pull request #473 from appsembler/optimize_cert_count
Browse files Browse the repository at this point in the history
faster total_site_certificates_as_of_date
  • Loading branch information
OmarIthawi authored Oct 13, 2022
2 parents afefb85 + 11a0690 commit 7d6ae30
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions figures/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ def total_site_certificates_as_of_date(site, date_for):
return data['num_learners_completed__sum']
```
"""
qs = CourseDailyMetrics.objects.filter(
latest_daily_metrics = CourseDailyMetrics.objects.filter(
site=site,
date_for__lte=date_for).order_by('-date_for')
if qs:
latest_date = qs[0].date_for
date_for__lte=date_for).order_by('-date_for').first()
if latest_daily_metrics:
latest_date = latest_daily_metrics.date_for
recs = CourseDailyMetrics.objects.filter(site=site,
date_for=latest_date)
data = recs.aggregate(Sum('num_learners_completed'))
Expand Down

0 comments on commit 7d6ae30

Please sign in to comment.