Skip to content

Commit

Permalink
drops 'timefunc' decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbrooks committed Dec 12, 2021
1 parent 210e6cd commit ddac5d7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Takes a Django model, queryset or (app_name, model_name) tuple and optional para

## GeoJsonCachedQuerySet

This is a special form of CachedQuerySet which shoould generate valid GeoJSON features from a model or queryset. Note that the geometry field is expected to be a GeoJSON field not a geometry field.
This is a special form of CachedQuerySet which should generate valid GeoJSON features from a model or queryset. Note that the geometry field is expected to be a GeoJSON field not a geometry field.

## Development

Expand Down
24 changes: 1 addition & 23 deletions django_querycache/cacheman.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"""

import datetime
import functools
import logging
import time
from functools import reduce
from hashlib import md5
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union
Expand Down Expand Up @@ -74,21 +72,6 @@ def query_to_key(query: QuerySet, suffix: str = "") -> str:
return f"{query.query.base_table}_{query_hex}{params_hex}{suffix}"


def timefunc(func):
"""Decorator function to log time taken by a function (in ms)"""

@functools.wraps(func)
def time_closure(*args, **kwargs):
"""Wrapped function will log the ms the function took"""
start = time.perf_counter()
result = func(*args, **kwargs)
time_elapsed = time.perf_counter() - start
logger.info(f"Function: {func.__name__}, Time: {(time_elapsed * 1000):.1f} ms")
return result

return time_closure


def get_query_cache(cache_alias: str = "default"):
"""
For purposes of caching, particularly in local dev,
Expand Down Expand Up @@ -272,7 +255,6 @@ def hexxor(a: hstring, b: hstring) -> hstring:

return reduce(hexxor, row_fingerprints(), "00000000")

@timefunc
def update_required(self, force_check=False) -> bool:
"""
Return whether the cached query is considered "dirty" and
Expand Down Expand Up @@ -496,7 +478,6 @@ def cached_query(self, value):
logger.debug("Refreshing cache for %s", self.cache_key)
self.cache.set(self.cache_key, value)

@timefunc
def get_with_update(self) -> Any:
"""
Return the cached query if fresh else
Expand Down Expand Up @@ -527,7 +508,6 @@ def update_if_required(self):
else:
logger.info("Fingerprint was recent or unchanged")

@timefunc
def update_cache(self):
if self._cache_is_dummy:
return
Expand Down Expand Up @@ -573,8 +553,7 @@ def feature_props(self, item: Type[Model]) -> dict:
"""
return {field: getattr(item, field) for field in self.geojson_props}

@timefunc
def get_serialized_query(self) -> List[Feature]:
def get_serialized_query(self) -> List[Feature]: # type: ignore
"""
Django has a built in geometry serializer
It does not work here because it requires geom to be
Expand All @@ -594,7 +573,6 @@ def get_serialized_query(self) -> List[Feature]:
for item in self.query
]

@timefunc
def features(self) -> List[Feature]:
"""
This will update the features in the cache if necessary and return them
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-querycache"
version = "0.1.5"
version = "0.1.6"
description = "Cache manager for Django querysets and serialization"
authors = ["Joshua Brooks <[email protected]>"]
license = "GPLv3"
Expand Down

0 comments on commit ddac5d7

Please sign in to comment.