Skip to content

Commit

Permalink
fixes bug 1143126 - avoid MemcachedKeyLengthError on analyze_model_fe…
Browse files Browse the repository at this point in the history
…tches
  • Loading branch information
peterbe committed Mar 13, 2015
1 parent 0384757 commit 749ecad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions webapp-django/crashstats/crashstats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions webapp-django/crashstats/manage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy
import urllib
import collections
import hashlib

from django import http
from django.conf import settings
Expand Down Expand Up @@ -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']
)
Expand Down

0 comments on commit 749ecad

Please sign in to comment.