diff --git a/CHANGES.rst b/CHANGES.rst index 219485fd..b62fb0e4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,8 @@ There's a frood who really knows where his towel is. 2.10.2 (unreleased) ^^^^^^^^^^^^^^^^^^^ -- Nothing changed yet. +- Remove useless scale caching on the request as it seems to be causing colateral issues (closes `#109 `_). + [rodfersou] 2.10.1 (2017-08-02) diff --git a/sc/social/like/utils.py b/sc/social/like/utils.py index ca4e3d09..042f5fb0 100644 --- a/sc/social/like/utils.py +++ b/sc/social/like/utils.py @@ -4,71 +4,55 @@ from Products.CMFPlone.utils import safe_hasattr from sc.social.like.logger import logger from urlparse import urlparse -from zope.annotation.interfaces import IAnnotations -from zope.globalrequest import getRequest from zope.interface import Invalid def get_images_view(context): - request = getRequest() - key = 'cache-view-' + str(context) - cache = IAnnotations(request) - value = cache.get(key, None) - if not value: - view = context.unrestrictedTraverse('@@images', None) - field = 'image' - if view: - fields = ['image', 'leadImage', 'portrait'] - if IBaseContent.providedBy(context): - schema = context.Schema() - field = [f for f in schema.keys() if f in fields] - if field: - field = field[0] - # if a content has an image field that isn't an ImageField - # (for example a relation field), set field='' to avoid errors - if schema[field].type not in ['image', 'blob']: - field = '' - value = (view, field) if (view and field) else (None, None) - cache[key] = value - return value + view = context.unrestrictedTraverse('@@images', None) + field = 'image' + if view: + fields = ['image', 'leadImage', 'portrait'] + if IBaseContent.providedBy(context): + schema = context.Schema() + field = [f for f in schema.keys() if f in fields] + if field: + field = field[0] + # if a content has an image field that isn't an ImageField + # (for example a relation field), set field='' to avoid errors + if schema[field].type not in ['image', 'blob']: + field = '' + return (view, field) if (view and field) else (None, None) def get_content_image(context, scale='large', width=None, height=None): - request = getRequest() - modification = context.ModificationDate() - key = 'cache-{0}-{1}-{2}-{3}-{4}'.format( - context, modification, scale, width, height) - cache = IAnnotations(request) - img = cache.get(key, None) - if not img: - view, field = get_images_view(context) - if view: + view, field = get_images_view(context) + img = None + if view: + try: + sizes = view.getImageSize(field) + except AttributeError: + sizes = img = None + if sizes == (0, 0) or sizes == ('', ''): + # this avoid strange cases where we can't get size infos. + # for example if the loaded image in a news is a bmp or a tiff + return None + if sizes: + kwargs = {} + if not (width or height): + kwargs['scale'] = scale + else: + new = (width, height) + width, height = _image_size(sizes, new) + kwargs['width'] = width + kwargs['height'] = height + kwargs['direction'] = 'down' try: - sizes = view.getImageSize(field) - except AttributeError: - sizes = img = None - if sizes == (0, 0) or sizes == ('', ''): - # this avoid strange cases where we can't get size infos. - # for example if the loaded image in a news is a bmp or a tiff - return None - if sizes: - kwargs = {} - if not (width or height): - kwargs['scale'] = scale - else: - new = (width, height) - width, height = _image_size(sizes, new) - kwargs['width'] = width - kwargs['height'] = height - kwargs['direction'] = 'down' - try: - img = view.scale(fieldname=field, **kwargs) - except (AttributeError, TypeError): - img = None - cache[key] = img + img = view.scale(fieldname=field, **kwargs) + except (AttributeError, TypeError): + img = None return img