summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2015-06-01 16:57:23 -0500
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2015-06-05 18:27:27 +0000
commit24232ceaa2496795629a166ffb00bb49ac306978 (patch)
treed9ab7b8d57746e0b13f1dc9234dd5113aab27b9f
parent9e5b5f2be2f8c275d6ef4556b75b3e91df4ee28b (diff)
downloadlinaro-patchmetrics-24232ceaa2496795629a166ffb00bb49ac306978.tar.gz
improve performance of "teams" overview page
This page was impossibly slow. Now its only really slow. This can't be improved until we have a better way to track patch contributions. This change causes us to have an unused function which I was happy to remove Change-Id: If240965cd5b04d681ed28afb9c017a683ac854e1
-rw-r--r--apps/patchmetrics/models.py39
-rw-r--r--apps/patchmetrics/tests/models.py33
-rw-r--r--apps/patchmetrics/views.py22
-rw-r--r--templates/patchmetrics/teams.html4
4 files changed, 9 insertions, 89 deletions
diff --git a/apps/patchmetrics/models.py b/apps/patchmetrics/models.py
index 6712064..5056cbc 100644
--- a/apps/patchmetrics/models.py
+++ b/apps/patchmetrics/models.py
@@ -1,5 +1,5 @@
import calendar
-from datetime import date, datetime, timedelta
+from datetime import datetime, timedelta
from dateutil import relativedelta
@@ -270,43 +270,6 @@ def get_distinct_author_count(year, month):
return patches.values('author').distinct().count()
-def get_patches_per_month_up_to(year, month, count_function, limit=None):
- """Return two lists with patches submitted and accepted per month.
-
- Each list will include counts for the months between PATCH_TRACKING_EPOCH
- and the given month.
-
- Each element in those lists is of the form [timestamp, count], with the
- timestamp in miliseconds.
-
- If a limit is specified, return the counts for up to limit previous
- months.
-
- :param count_function: A callable which takes a start and end date and
- return a two-tuple with the number of submitted and accepted patches
- for that time period.
- """
- start_date = PATCH_TRACKING_EPOCH
- end_date = (start_date + relativedelta.relativedelta(months=1) -
- timedelta(seconds=1))
- accepted = []
- submitted = []
- current_date = date(year, month, 1)
- while start_date.date() <= current_date:
- month_timestamp = calendar.timegm(start_date.timetuple()) * 1000
- n_submitted, n_accepted = count_function(start_date, end_date)
- submitted.append([month_timestamp, n_submitted])
- accepted.append([month_timestamp, n_accepted])
- start_date = end_date + timedelta(seconds=1)
- end_date = (start_date + relativedelta.relativedelta(months=1) -
- timedelta(seconds=1))
- while limit is not None and len(submitted) > limit:
- # Pop from the beginning as those as the oldest months.
- submitted.pop(0)
- accepted.pop(0)
- return submitted, accepted
-
-
def get_number_of_old_patches_accepted_on_month(year, month):
"""Return the number of patches submitted on previous months that were
accepted on the given month.
diff --git a/apps/patchmetrics/tests/models.py b/apps/patchmetrics/tests/models.py
index e289106..e0cca4b 100644
--- a/apps/patchmetrics/tests/models.py
+++ b/apps/patchmetrics/tests/models.py
@@ -10,7 +10,6 @@ from patchmetrics.models import (
GerritChange,
get_distinct_author_count,
get_overall_patch_count,
- get_patches_per_month_up_to,
get_patches_accepted_by_age_range,
get_patches_waiting_for_feedback_by_age_range,
get_submitted_patch_counts_for_month,
@@ -113,38 +112,6 @@ class TestChartHelpers(TestCase):
self.assertEqual(
(2, 1), get_submitted_patch_counts_for_month(now.year, now.month))
- def test_get_patches_per_month_up_to(self):
- patch1 = factory.makeLinaroPatch()
- patch2 = factory.makeLinaroPatch(state_name='Accepted')
- now = datetime.now()
- last_month = now - relativedelta.relativedelta(months=1)
- patch3 = factory.makeLinaroPatch(date=last_month)
- # Although we have a patch from 3 months ago we won't get a count for
- # that month because we'll ask get_overall_patches_per_month_up_to to
- # give us the counts for the last two months (this one and the
- # previous) only.
- three_months_ago = now - relativedelta.relativedelta(months=3)
- patch4 = factory.makeLinaroPatch(date=three_months_ago)
- # Monkey-patch PATCH_TRACKING_EPOCH to make the results predictable.
- orig_epoch = models.PATCH_TRACKING_EPOCH
- models.PATCH_TRACKING_EPOCH = datetime(
- year=last_month.year, month=three_months_ago.month, day=1)
- try:
- submitted, accepted = get_patches_per_month_up_to(
- now.year, now.month, get_overall_patch_count, limit=2)
- finally:
- models.PATCH_TRACKING_EPOCH = orig_epoch
-
- # get_overall_patches_per_month_up_to() returns timestamps in
- # miliseconds so we need to divide them by 1000 here.
- submitted = [(time.gmtime(timestamp / 1000).tm_mon, count)
- for timestamp, count in submitted]
- self.assertEqual([(last_month.month, 1), (now.month, 2)], submitted)
-
- accepted = [(time.gmtime(timestamp / 1000).tm_mon, count)
- for timestamp, count in accepted]
- self.assertEqual([(last_month.month, 0), (now.month, 1)], accepted)
-
def test_get_patches_accepted_by_age_range(self):
four_days_ago = datetime.now() - timedelta(days=4)
patch1 = factory.makeLinaroPatch(state_name='Accepted')
diff --git a/apps/patchmetrics/views.py b/apps/patchmetrics/views.py
index 123af9c..c6b62fb 100644
--- a/apps/patchmetrics/views.py
+++ b/apps/patchmetrics/views.py
@@ -15,7 +15,6 @@ from patchmetrics.models import (
get_number_of_patches_accepted,
get_number_of_patches_waiting_for_feedback,
get_patches_accepted_by_age_range,
- get_patches_per_month_up_to,
get_patches_waiting_for_feedback_by_age_range,
get_oldest_patches_waiting_for_feedback,
patch_count_by_month,
@@ -107,23 +106,14 @@ def team_user(request, team_id, user):
def overall_teams_report(request):
context = PatchworkRequestContext(request)
- one_month_ago = datetime.now() - relativedelta.relativedelta(months=1)
teams_data = []
- months = []
for team in Team.objects.all().order_by('display_name'):
- submitted, accepted = get_patches_per_month_up_to(
- one_month_ago.year, one_month_ago.month, team.get_patch_count,
- limit=8)
- if len(months) == 0:
- for item in submitted:
- # The timestamps returned by get_patches_per_month_up_to() are
- # in milliseconds so we need to divide them by 1000 here.
- month = datetime.utcfromtimestamp(item[0] / 1000).month
- months.append(calendar.month_name[month])
- submitted = [item[1] for item in submitted]
- accepted = [item[1] for item in accepted]
- counts = zip(submitted, accepted)
- teams_data.append([team, counts])
+ teams_data.append((team, patch_month_metrics(team.patches)))
+ months = []
+ for x in teams_data[0][1]:
+ # go from ms to "month"
+ month = datetime.utcfromtimestamp(x[0] / 1000).month
+ months.append(calendar.month_name[month])
context['teams_data'] = teams_data
context['months'] = months
return render_to_response('patchmetrics/teams.html', context)
diff --git a/templates/patchmetrics/teams.html b/templates/patchmetrics/teams.html
index 143547a..cdf2e1a 100644
--- a/templates/patchmetrics/teams.html
+++ b/templates/patchmetrics/teams.html
@@ -22,8 +22,8 @@
>{{team_data.0.display_name}}</a>
</td>
{% for count in team_data.1 %}
- <td style="text-align: right">{{ count.0 }}
- (<span style="color: green">{{ count.1 }}</span>)</td>
+ <td style="text-align: right">{{ count.1 }}
+ (<span style="color: green">{{ count.2 }}</span>)</td>
{% endfor %}
</tr>
{% endfor %}