From deb030c1fd4aa11f079df92064c7b243c3ebda66 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 25 Nov 2013 21:58:41 -0600 Subject: Old TODO file is very out of date Signed-off-by: Dan McGee --- TODO | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index 608d8470..00000000 --- a/TODO +++ /dev/null @@ -1,4 +0,0 @@ -TODO: - - refactor stats by templates in dashboard, maybe a templatetag - - -- cgit v1.2.3-2-g168b From 2751e3870ea7875a67b42d025ca0369cf0a1bebf Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 14 Dec 2013 09:10:38 -0600 Subject: Bump Django requirement for minor version release Signed-off-by: Dan McGee --- requirements.txt | 2 +- requirements_prod.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7ff363e6..de8a04e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -e git+git://github.com/fredj/cssmin.git@master#egg=cssmin -Django==1.6 +Django==1.6.1 IPy==0.81 Markdown==2.3.1 South==0.8.4 diff --git a/requirements_prod.txt b/requirements_prod.txt index 3f2958c6..e609c5d6 100644 --- a/requirements_prod.txt +++ b/requirements_prod.txt @@ -1,5 +1,5 @@ -e git+git://github.com/fredj/cssmin.git@master#egg=cssmin -Django==1.6 +Django==1.6.1 IPy==0.81 Markdown==2.3.1 South==0.8.4 -- cgit v1.2.3-2-g168b From cd427ead7e71bb5d7716f015b1f9753ee56a9b4e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 1 Dec 2013 23:17:07 -0600 Subject: Fix double space in template Signed-off-by: Dan McGee --- templates/mirrors/status.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/mirrors/status.html b/templates/mirrors/status.html index 331c18ee..e97ad4ba 100644 --- a/templates/mirrors/status.html +++ b/templates/mirrors/status.html @@ -59,7 +59,7 @@

Out of Sync Mirrors

- {% with urls=bad_urls table_id='outofsync_mirrors' %} + {% with urls=bad_urls table_id='outofsync_mirrors' %} {% include "mirrors/status_table.html" %} {% endwith %} -- cgit v1.2.3-2-g168b From 3b1b677b49af194313da766579e9fa1a021afd84 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 1 Dec 2013 23:15:30 -0600 Subject: Speed up master key listing page We were spending a lot of time getting the developer name for a given key on this page, which involved sending one query per key ID. Use the cache to our advantage here and save ourselves the "expensive" lookups. This eliminates ~100 queries per page load. Signed-off-by: Dan McGee --- main/templatetags/pgp.py | 18 +++++++++++++----- templates/public/keys.html | 8 ++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py index e93e5bca..cc080439 100644 --- a/main/templatetags/pgp.py +++ b/main/templatetags/pgp.py @@ -3,6 +3,7 @@ from django.conf import settings from django.utils.html import conditional_escape from django.utils.safestring import mark_safe +from ..utils import cache_function from devel.models import DeveloperKey register = template.Library() @@ -42,15 +43,22 @@ def pgp_key_link(key_id, link_text=None): values = (url, format_key(key_id), link_text) return '%s' % values -@register.simple_tag -def user_pgp_key_link(key_id): - normalized = key_id[-16:] + +@cache_function(1800) +def name_for_key(normalized): try: matching_key = DeveloperKey.objects.select_related( 'owner').get(key=normalized, owner_id__isnull=False) + return matching_key.owner.get_full_name() except DeveloperKey.DoesNotExist: - return pgp_key_link(key_id) - return pgp_key_link(key_id, matching_key.owner.get_full_name()) + return None + + +@register.simple_tag +def user_pgp_key_link(key_id): + normalized = key_id[-16:] + name = name_for_key(normalized) + return pgp_key_link(key_id, name) @register.filter(needs_autoescape=True) diff --git a/templates/public/keys.html b/templates/public/keys.html index c7272db3..54d52ab8 100644 --- a/templates/public/keys.html +++ b/templates/public/keys.html @@ -86,16 +86,16 @@ - {% for user in active_users %} + {% for user in active_users %}{% with user_key=user.userprofile.pgp_key %} {{ user.get_full_name }} - {% pgp_key_link user.userprofile.pgp_key %} + {% pgp_key_link user_key %} {% spaceless %}{% for key in keys %} - {% signature_exists signatures key.pgp_key user.userprofile.pgp_key as signed %} + {% signature_exists signatures key.pgp_key user_key as signed %} {{ signed|yesno|capfirst }} {% endfor %}{% endspaceless %} - {% endfor %} + {% endwith %}{% endfor %} -- cgit v1.2.3-2-g168b From ecece25814042d262bb7a102b9cbe48fc9c87db4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 1 Dec 2013 11:42:25 -0600 Subject: Show all mirror status data to authorized users Regardless of whether the mirror URL is active or not, we often have data we can show the end user, especially if mirror admins care to see the data we've been gathering. Signed-off-by: Dan McGee --- mirrors/utils.py | 20 +++++++++++--------- mirrors/views.py | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mirrors/utils.py b/mirrors/utils.py index 633731a7..9f40bca6 100644 --- a/mirrors/utils.py +++ b/mirrors/utils.py @@ -113,18 +113,17 @@ def annotate_url(url, url_data): url.score = (hours + url.duration_avg + stddev) / divisor -def get_mirror_statuses(cutoff=DEFAULT_CUTOFF, mirror_id=None): +def get_mirror_statuses(cutoff=DEFAULT_CUTOFF, mirror_id=None, show_all=False): cutoff_time = now() - cutoff - # TODO: this prevents grabbing data points from any mirror that was active, - # receiving checks, and then marked private. we can probably be smarter and - # filter the data later? - valid_urls = MirrorUrl.objects.filter(active=True, - mirror__active=True, mirror__public=True, + valid_urls = MirrorUrl.objects.filter( logs__check_time__gte=cutoff_time).distinct() if mirror_id: valid_urls = valid_urls.filter(mirror_id=mirror_id) + if not show_all: + valid_urls = valid_urls.filter(active=True, mirror__active=True, + mirror__public=True) url_data = status_data(cutoff_time, mirror_id) urls = MirrorUrl.objects.select_related('mirror', 'protocol').filter( @@ -159,11 +158,11 @@ def get_mirror_statuses(cutoff=DEFAULT_CUTOFF, mirror_id=None): } -def get_mirror_errors(cutoff=DEFAULT_CUTOFF, mirror_id=None): +def get_mirror_errors(cutoff=DEFAULT_CUTOFF, mirror_id=None, show_all=False): cutoff_time = now() - cutoff errors = MirrorLog.objects.filter( - is_success=False, check_time__gte=cutoff_time, url__active=True, - url__mirror__active=True, url__mirror__public=True).values( + is_success=False, check_time__gte=cutoff_time, + url__mirror__public=True).values( 'url__url', 'url__country', 'url__protocol__protocol', 'url__mirror__tier', 'error').annotate( error_count=Count('error'), last_occurred=Max('check_time') @@ -171,6 +170,9 @@ def get_mirror_errors(cutoff=DEFAULT_CUTOFF, mirror_id=None): if mirror_id: errors = errors.filter(url__mirror_id=mirror_id) + if not show_all: + errors = errors.filter(url__active=True, url__mirror__active=True, + url__mirror__public=True) errors = list(errors) for err in errors: diff --git a/mirrors/views.py b/mirrors/views.py index ec056696..9e05e5fc 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -153,15 +153,20 @@ def mirrors(request): def mirror_details(request, name): mirror = get_object_or_404(Mirror, name=name) - if not request.user.is_authenticated() and \ + authorized = request.user.is_authenticated() + if not authorized and \ (not mirror.public or not mirror.active): raise Http404 error_cutoff = timedelta(days=7) - status_info = get_mirror_statuses(mirror_id=mirror.id) + status_info = get_mirror_statuses(mirror_id=mirror.id, + show_all=authorized) checked_urls = {url for url in status_info['urls'] \ if url.mirror_id == mirror.id} - all_urls = set(mirror.urls.filter(active=True).select_related('protocol')) + all_urls = mirror.urls.select_related('protocol') + if not authorized: + all_urls = all_urls.filter(active=True) + all_urls = set(all_urls) # Add dummy data for URLs that we haven't checked recently other_urls = all_urls.difference(checked_urls) for url in other_urls: @@ -170,7 +175,8 @@ def mirror_details(request, name): setattr(url, attr, None) all_urls = sorted(checked_urls.union(other_urls), key=attrgetter('url')) - error_logs = get_mirror_errors(mirror_id=mirror.id, cutoff=error_cutoff) + error_logs = get_mirror_errors(mirror_id=mirror.id, cutoff=error_cutoff, + show_all=True) context = { 'mirror': mirror, @@ -181,8 +187,10 @@ def mirror_details(request, name): return render(request, 'mirrors/mirror_details.html', context) def mirror_details_json(request, name): + authorized = request.user.is_authenticated() mirror = get_object_or_404(Mirror, name=name) - status_info = get_mirror_statuses(mirror_id=mirror.id) + status_info = get_mirror_statuses(mirror_id=mirror.id, + show_all=authorized) data = status_info.copy() data['version'] = 3 to_json = json.dumps(data, ensure_ascii=False, -- cgit v1.2.3-2-g168b