Skip to content

Commit

Permalink
Merge pull request hackforla#1022 from hackforla/report-cache
Browse files Browse the repository at this point in the history
Report cache
  • Loading branch information
mattyweb authored Mar 12, 2021
2 parents 235cc82 + 57b747b commit 2d56b08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/api/code/lacity_data_api/services/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..models.council import Council
from ..models.source import Source
from ..models.agency import Agency
from .utilities import cache_key


# maps keywords to sqlalchemy columns or functions
Expand Down Expand Up @@ -39,7 +40,7 @@
filter_regex = "^(\w+)([>=<]+)([\w-]+)$" # noqa


@cached(alias="default")
@cached(key_builder=cache_key, alias="default")
async def run_report(field, filter):

# set up the fields for select and group by
Expand Down
13 changes: 12 additions & 1 deletion server/api/code/lacity_data_api/services/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ def classmethod_cache_key(f, *args, **kwargs):
return format(str(f.__qualname__) + str(args[1:]))


def cache_key(f, *args, **kwargs):
"""
Utility function to create shorter keys for methods
"""
return format(
str(f.__module__).split('.')[-1].capitalize() +
'.' +
str(f.__qualname__) + str(args)
)


# TODO: maybe recessitate this for object keys (e.g. filters)
# def cache_key(f, *args, **kwargs):
# def hashed_cache_key(f, *args, **kwargs):
# """
# Utility function to create hashed key for pins based on filters
# """
Expand Down

0 comments on commit 2d56b08

Please sign in to comment.