Permalink
Browse files

Merge pull request #2661 from peterbe/bug-1143126-possible-memcachedk…

…eylengtherror-on-analyze_model_fetches-view

fixes bug 1143126 - avoid MemcachedKeyLengthError on analyze_model_fetches
  • Loading branch information...
peterbe committed Mar 13, 2015
2 parents 0384757 + 749ecad commit 6d46c4bc9d3c58035bd586356741ad6673ca5245
Showing with 10 additions and 8 deletions.
  1. +3 −3 webapp-django/crashstats/crashstats/models.py
  2. +7 −5 webapp-django/crashstats/manage/views.py
@@ -156,10 +156,10 @@ def inner(*args, **kwargs):
if value not in all:
all.append(value)
cache.set(key, all, 60 * 60 * 24)
valuekey = hashlib.md5(value.encode('utf-8')).hexdigest()
for prefix, incr in (('times', msecs), ('uses', 1)):
key = '%s_%s_%s' % (prefix, hit_or_miss, value)
# memcache is max 250 but raises warnings >240
key = key[:240]
key = '%s_%s_%s' % (prefix, hit_or_miss, valuekey)
try:
cache.incr(key, incr)
except ValueError:
@@ -4,6 +4,7 @@
import copy
import urllib
import collections
import hashlib
from django import http
from django.conf import settings
@@ -409,17 +410,18 @@ def analyze_model_fetches(request):
all = cache.get('all_%s' % value_type) or []
records = []
for item in all:
item = item[:220]
itemkey = hashlib.md5(item.encode('utf-8')).hexdigest()
data = {}
data['times'] = {}
data['times']['hits'] = cache.get('times_HIT_%s' % item, 0)
data['times']['misses'] = cache.get('times_MISS_%s' % item, 0)
data['times']['hits'] = cache.get('times_HIT_%s' % itemkey, 0)
data['times']['misses'] = cache.get('times_MISS_%s' % itemkey, 0)
data['times']['both'] = (
data['times']['hits'] + data['times']['misses']
)
data['uses'] = {}
data['uses']['hits'] = cache.get('uses_HIT_%s' % item, 0)
data['uses']['misses'] = cache.get('uses_MISS_%s' % item, 0)
data['uses']['hits'] = cache.get('uses_HIT_%s' % itemkey, 0)
data['uses']['misses'] = cache.get('uses_MISS_%s' % itemkey, 0)
data['uses']['both'] = (
data['uses']['hits'] + data['uses']['misses']
)

0 comments on commit 6d46c4b

Please sign in to comment.