From ddac5d733a59241e3d29f3d71cf8052d9b7b1172 Mon Sep 17 00:00:00 2001 From: Joshua Brooks Date: Mon, 13 Dec 2021 00:13:28 +0900 Subject: [PATCH] drops 'timefunc' decorator --- README.md | 2 +- django_querycache/cacheman.py | 24 +----------------------- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 4aa3d93..f05cefb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/django_querycache/cacheman.py b/django_querycache/cacheman.py index 1780c7f..8a2e587 100644 --- a/django_querycache/cacheman.py +++ b/django_querycache/cacheman.py @@ -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 @@ -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, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index fd69953..19baa56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "GPLv3"