~sircmpwn/todo.sr.ht

e101e7eecac720a75f7cb8648d965f8648212f85 — Drew DeVault a month ago 94c954f 0.58.6
Utilize srht.cache instead of direct Redis access

This also removes some outdated dependencies in setup.py that were found
while grepping around for redis use-cases.
2 files changed, 3 insertions(+), 5 deletions(-)

M setup.py
M todosrht/filters.py
M setup.py => setup.py +0 -2
@@ 32,9 32,7 @@ setup(
  author_email = 'sir@cmpwn.com',
  url = 'https://todo.sr.ht/~sircmpwn/todo.sr.ht',
  install_requires = [
    'alembic',
    'pystache',
    'redis',
    'srht',
  ],
  license = 'AGPL-3.0',

M todosrht/filters.py => todosrht/filters.py +3 -3
@@ 6,7 6,7 @@ from functools import wraps
from jinja2.utils import Markup, escape
from srht.flask import icon, csrf_token, date_handler
from srht.markdown import markdown, SRHT_MARKDOWN_VERSION 
from srht.redis import redis
from srht.cache import get_cache, set_cache
from todosrht import urls
from todosrht.tickets import find_mentioned_users, find_mentioned_tickets
from todosrht.tickets import TICKET_MENTION_PATTERN, USER_MENTION_PATTERN


@@ 18,12 18,12 @@ def cache_rendered_markup(func):
        sha = hashlib.sha1()
        sha.update(json.dumps(obj.to_dict(), default=date_handler).encode())
        key = f"todo.sr.ht:cache_rendered_markup:{class_name}:{sha.hexdigest()}:v{SRHT_MARKDOWN_VERSION}"
        value = redis.get(key)
        value = get_cache(key)
        if value:
            return Markup(value.decode())

        value = func(obj)
        redis.setex(key, timedelta(days=30), value)
        set_cache(key, timedelta(days=30), value)
        return value
    return wrap