Skip to content

Commit c28435f

Browse files
committed
Merge pull request #20 from fabiobatalha/tk19
Gerando md5 para chaves de cache muito grandes
2 parents ad5d3f4 + ac71100 commit c28435f

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

analytics/utils.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import weakref
44
import re
55
import unicodedata
6+
import hashlib
67

78
try:
89
from ConfigParser import SafeConfigParser
@@ -19,23 +20,29 @@ def dogpile_controller_key_generator(namespace, fn, *kwargs):
1920

2021
def generate_key(*the_args, **the_kwargs):
2122

22-
key = [
23+
tp = tuple([
2324
str(namespace),
24-
str(fname)
25-
]
26-
key += [str(i) for i in the_args[1:]]
27-
key.append(str(the_kwargs))
25+
str(fname),
26+
str(the_args[1:]),
27+
tuple(the_kwargs.items())
28+
])
2829

29-
return "_".join(key)
30+
return str(hash(tp))
3031

3132
return generate_key
3233

3334

34-
def clean_string(data):
35-
nfkd_form = unicodedata.normalize('NFKD', data.strip())
36-
source = u"".join([c for c in nfkd_form if not unicodedata.combining(c)])
35+
def clean_string(text):
36+
37+
try:
38+
nfd_form = unicodedata.normalize('NFD', text.strip().lower())
39+
except:
40+
return text
41+
42+
cleaned_str = u''.join(x for x in nfd_form if unicodedata.category(x)[0] == 'L' or x == ' ')
43+
44+
return cleaned_str
3745

38-
return source.strip().lower()
3946

4047
class SingletonMixin(object):
4148
"""

0 commit comments

Comments
 (0)