From 2314eadfa920ad24bad50609cb42bfdfaa4ad8a7 Mon Sep 17 00:00:00 2001 From: Owocki Date: Fri, 2 Nov 2018 23:38:49 +0100 Subject: [PATCH] leaderboard goodness, re-enables location leaderboards with caching -- time profile: real 13m38.270s user 5m54.660s sys 1m0.440s --- .../commands/assemble_leaderboards.py | 20 ++++++++++++++++--- app/marketing/views.py | 6 +++--- app/retail/templates/results.html | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/marketing/management/commands/assemble_leaderboards.py b/app/marketing/management/commands/assemble_leaderboards.py index a29cfa3d82f..8e700fc3c9c 100644 --- a/app/marketing/management/commands/assemble_leaderboards.py +++ b/app/marketing/management/commands/assemble_leaderboards.py @@ -17,6 +17,7 @@ along with this program. If not, see . """ +from cacheops import CacheMiss, cache from django.conf import settings from django.core.management.base import BaseCommand from django.utils import timezone @@ -76,9 +77,22 @@ def default_ranks(): def profile_to_location(handle): - # TODO (mbeacom): Debug, fix, and re-enable leaderboards by location on live. - if settings.ENV == 'prod': - return [] + timeout = 60 * 20 + key_salt = '1' + key = f'profile_to_location{handle}_{key_salt}' + try: + results = cache.get(key) + except CacheMiss: + results = None + + if not results: + results = profile_to_location_helper(handle) + cache.set(key, results, timeout) + + return results + + +def profile_to_location_helper(handle): profiles = Profile.objects.filter(handle__iexact=handle) if handle and profiles.exists(): diff --git a/app/marketing/views.py b/app/marketing/views.py index 909997afd52..271b736ad51 100644 --- a/app/marketing/views.py +++ b/app/marketing/views.py @@ -598,9 +598,9 @@ def leaderboard(request, key=''): 'quarterly_tokens': _('Top Tokens'), 'quarterly_keywords': _('Top Keywords'), 'quarterly_kudos': _('Top Kudos'), - # 'quarterly_cities': _('Top Cities'), - # 'quarterly_countries': _('Top Countries'), - # 'quarterly_continents': _('Top Continents'), + 'quarterly_cities': _('Top Cities'), + 'quarterly_countries': _('Top Countries'), + 'quarterly_continents': _('Top Continents'), # 'weekly_fulfilled': 'Weekly Leaderboard: Fulfilled Funded Issues', # 'weekly_all': 'Weekly Leaderboard: All Funded Issues', # 'monthly_fulfilled': 'Monthly Leaderboard', diff --git a/app/retail/templates/results.html b/app/retail/templates/results.html index 8618cc07535..a7563f7f348 100644 --- a/app/retail/templates/results.html +++ b/app/retail/templates/results.html @@ -74,7 +74,7 @@
{% trans "and by Type" %}

- Since it's launch in November 2017, Gitcoin has helped {{funders|intcomma}} funders reach an audience of {{audience|intcomma}} developers. Gitcoin has facilitated {{transactions|intcomma}} complete transactions to {{recipients|intcomma}} unique coders. + Since its launch in November 2017, Gitcoin has helped {{funders|intcomma}} funders reach an audience of {{audience|intcomma}} developers. Gitcoin has facilitated {{transactions|intcomma}} complete transactions to {{recipients|intcomma}} unique coders.