add routing stats because heck why not
This commit is contained in:
parent
82af80edb7
commit
0d7cb37759
2 changed files with 21 additions and 4 deletions
|
@ -44,6 +44,13 @@ def optimize_query(qs):
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
def api_stats_clean_location_value(value):
|
||||||
|
if isinstance(value, str) and value.startswith('c:'):
|
||||||
|
value = value.split(':')
|
||||||
|
value = 'c:%s:%d:%d' % (value[1], int(float(value[2]) / 3) * 3, int(float(value[3]) / 3) * 3)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def api_stats(view_name):
|
def api_stats(view_name):
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
|
@ -51,10 +58,7 @@ def api_stats(view_name):
|
||||||
response = func(self, request, *args, **kwargs)
|
response = func(self, request, *args, **kwargs)
|
||||||
if response.status_code < 400 and kwargs:
|
if response.status_code < 400 and kwargs:
|
||||||
name, value = next(iter(kwargs.items()))
|
name, value = next(iter(kwargs.items()))
|
||||||
if isinstance(value, str) and value.startswith('c:'):
|
increment_cache_key('apistats__%s__%s__%s' % (view_name, name, api_stats_clean_location_value(value)))
|
||||||
value = value.split(':')
|
|
||||||
value = 'c:%s:%d:%d' % (value[1], int(float(value[2])/3)*3, int(float(value[3])/3)*3)
|
|
||||||
increment_cache_key('apistats__%s__%s__%s' % (view_name, name, value))
|
|
||||||
return response
|
return response
|
||||||
return wrapped_func
|
return wrapped_func
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
@ -4,7 +4,9 @@ from rest_framework.decorators import action
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.viewsets import ViewSet
|
from rest_framework.viewsets import ViewSet
|
||||||
|
|
||||||
|
from c3nav.mapdata.api import api_stats_clean_location_value
|
||||||
from c3nav.mapdata.models.access import AccessPermission
|
from c3nav.mapdata.models.access import AccessPermission
|
||||||
|
from c3nav.mapdata.utils.cache.stats import increment_cache_key
|
||||||
from c3nav.mapdata.utils.locations import visible_locations_for_request
|
from c3nav.mapdata.utils.locations import visible_locations_for_request
|
||||||
from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable
|
from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable
|
||||||
from c3nav.routing.forms import RouteForm
|
from c3nav.routing.forms import RouteForm
|
||||||
|
@ -55,6 +57,17 @@ class RoutingViewSet(ViewSet):
|
||||||
'error': _('No route found.'),
|
'error': _('No route found.'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
increment_cache_key('apistats__route_tuple_%s_%s' % (
|
||||||
|
api_stats_clean_location_value(form.cleaned_data['origin'].pk),
|
||||||
|
api_stats_clean_location_value(form.cleaned_data['destination'].pk),
|
||||||
|
))
|
||||||
|
increment_cache_key('apistats__route_origin_%s' % (
|
||||||
|
api_stats_clean_location_value(form.cleaned_data['origin'].pk),
|
||||||
|
))
|
||||||
|
increment_cache_key('apistats__route_destination_%s' % (
|
||||||
|
api_stats_clean_location_value(form.cleaned_data['destination'].pk),
|
||||||
|
))
|
||||||
|
|
||||||
return Response({
|
return Response({
|
||||||
'request': {
|
'request': {
|
||||||
'origin': form.cleaned_data['origin'].pk,
|
'origin': form.cleaned_data['origin'].pk,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue