Skip to content

Commit

Permalink
Add logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Oct 11, 2023
1 parent a7bb2ce commit 1f3dd9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions g3w-admin/core/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from guardian.exceptions import GuardianError
from guardian.utils import get_40x_or_None

import logging

logger = logging.getLogger('g3wadmin.debug')


def project_type_permission_required(perm, lookup_variables=None, **kwargs):
"""
Expand Down Expand Up @@ -155,6 +159,7 @@ def _decorator(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
key = f"{key_prefix}{'_'.join([str(kwargs[k]) for k in key_args] + [str(request.user.pk)])}"
logger.debug(f"[CACHING /api/config]: Key {key}")
response = cache.get(key)
if not response:
response = view_func(request, *args, **kwargs)
Expand Down
12 changes: 10 additions & 2 deletions g3w-admin/qdjango/models/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
setPermissionUserObject,
)

logger = logging.getLogger(__name__)
logger = logging.getLogger('g3wadmin.debug')

# Layer type with widget set capability
TYPE_LAYER_FOR_WIDGET = ("postgres", "spatialite", "ogr", "mssql", "virtual", "oracle")
Expand Down Expand Up @@ -523,16 +523,24 @@ def invalidate_cache(self, user=None):
"""Method to invalidate(delete) API REST /api/config"""

# invalidate project cache
pre_key = f"{settings.QDJANGO_PRJ_CACHE_KEY}{self.group.pk}_{'qdjango'}_{self.pk}"
pre_key = (
f"{settings.QDJANGO_PRJ_CACHE_KEY}{self.group.pk}_{'qdjango'}_{self.pk}"
)
if user == None:

# Invalidate every cache for every user
users = User.objects.all()
for user in users:
logger.debug(
f"[CACHING /api/config]: Ivalidate key {pre_key}_{str(user.pk)}"
)
cache.delete(f"{pre_key}_{str(user.pk)}")
else:

# Invalidate only for user
logger.debug(
f"[CACHING /api/config]: Ivalidate key {pre_key}_{str(user.pk)}"
)
cache.delete(f"{pre_key}_{str(user.pk)}")


Expand Down

0 comments on commit 1f3dd9f

Please sign in to comment.