From 847f23e93af7ed15de0e60a0f342b7a0f2cdbb16 Mon Sep 17 00:00:00 2001 From: fabiobatalha Date: Fri, 13 Nov 2015 17:13:41 -0200 Subject: [PATCH 1/3] Gerando md5 para chaves de cache muito grandes --- analytics/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/analytics/utils.py b/analytics/utils.py index 3b81a3a..d1df705 100644 --- a/analytics/utils.py +++ b/analytics/utils.py @@ -3,6 +3,7 @@ import weakref import re import unicodedata +import hashlib try: from ConfigParser import SafeConfigParser @@ -26,7 +27,12 @@ def generate_key(*the_args, **the_kwargs): key += [str(i) for i in the_args[1:]] key.append(str(the_kwargs)) - return "_".join(key) + finalkey = "_".join(key) + + if len(finalkey) > 249: + return hashlib.md5(finalkey).hexdigest() + + return finalkey return generate_key From 2f17f8abcab64f20bff488924d697c54174f644f Mon Sep 17 00:00:00 2001 From: fabiobatalha Date: Fri, 13 Nov 2015 17:59:09 -0200 Subject: [PATCH 2/3] Ajustes em metodo de limpeza de titulos para pesquisa --- analytics/utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/analytics/utils.py b/analytics/utils.py index d1df705..a43c8bc 100644 --- a/analytics/utils.py +++ b/analytics/utils.py @@ -37,11 +37,17 @@ def generate_key(*the_args, **the_kwargs): return generate_key -def clean_string(data): - nfkd_form = unicodedata.normalize('NFKD', data.strip()) - source = u"".join([c for c in nfkd_form if not unicodedata.combining(c)]) +def clean_string(text): + + try: + nfd_form = unicodedata.normalize('NFD', text.strip().lower()) + except: + return text + + cleaned_str = u''.join(x for x in nfd_form if unicodedata.category(x)[0] == 'L' or x == ' ') + + return cleaned_str - return source.strip().lower() class SingletonMixin(object): """ From ac71100d45fb8960528f7d13d16b2520c14248a7 Mon Sep 17 00:00:00 2001 From: fabiobatalha Date: Fri, 13 Nov 2015 18:48:18 -0200 Subject: [PATCH 3/3] =?UTF-8?q?Ajustes=20em=20gera=C3=A7=C3=A3o=20de=20cha?= =?UTF-8?q?ve=20de=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analytics/utils.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/analytics/utils.py b/analytics/utils.py index a43c8bc..297b193 100644 --- a/analytics/utils.py +++ b/analytics/utils.py @@ -20,19 +20,14 @@ def dogpile_controller_key_generator(namespace, fn, *kwargs): def generate_key(*the_args, **the_kwargs): - key = [ + tp = tuple([ str(namespace), - str(fname) - ] - key += [str(i) for i in the_args[1:]] - key.append(str(the_kwargs)) + str(fname), + str(the_args[1:]), + tuple(the_kwargs.items()) + ]) - finalkey = "_".join(key) - - if len(finalkey) > 249: - return hashlib.md5(finalkey).hexdigest() - - return finalkey + return str(hash(tp)) return generate_key