@@ -35,29 +35,32 @@ def filter_queryset(self, request, queryset, view):
35
35
filter_instance = self ._get_filter_instance (filter_class , queryset , view )
36
36
query = self .get_query (filter_instance , request , view )
37
37
38
- def apply_filters_lazy ():
39
- return filter_instance .apply_filters (query , request , view )
40
-
41
- if filter_class .QUERIES_CACHE_BACKEND and request .method in ('GET' , 'HEAD' , 'OPTIONS' ):
38
+ can_query_be_cached = all ((
39
+ filter_class .QUERIES_CACHE_BACKEND ,
40
+ filter_class .QUERIES_CACHE_SIZE ,
41
+ request .method in ('GET' , 'HEAD' , 'OPTIONS' ),
42
+ ))
43
+ if can_query_be_cached :
42
44
# We must use the combination of queryset and query to make a cache key as
43
45
# queryset can already contain some filters (e.x. based on authentication)
44
- cache_key = hash ( str (queryset .query ) + query )
46
+ cache_key = str (queryset .query ) + query
45
47
46
48
query_cache = self ._get_or_init_cache (filter_class , view )
47
49
filters_result = query_cache .get (cache_key )
48
50
if not filters_result :
49
- filters_result = apply_filters_lazy ( )
51
+ filters_result = filter_instance . apply_filters ( query , request , view )
50
52
query_cache [cache_key ] = filters_result
53
+
51
54
else :
52
- filters_result = apply_filters_lazy ( )
55
+ filters_result = filter_instance . apply_filters ( query , request , view )
53
56
54
57
rql_ast , queryset = filters_result
55
58
56
59
request .rql_ast = rql_ast
57
60
if queryset .select_data :
58
61
request .rql_select = queryset .select_data
59
62
60
- return queryset
63
+ return queryset . all ()
61
64
62
65
def get_schema_operation_parameters (self , view ):
63
66
spec = []
@@ -84,14 +87,14 @@ def get_query(cls, filter_instance, request, view):
84
87
85
88
@classmethod
86
89
def _get_or_init_cache (cls , filter_class , view ):
87
- qual_name = cls ._get_filter_cls_qual_name (filter_class , view )
90
+ qual_name = cls ._get_filter_cls_qual_name (view )
88
91
return cls ._CACHES .setdefault (
89
92
qual_name , filter_class .QUERIES_CACHE_BACKEND (int (filter_class .QUERIES_CACHE_SIZE )),
90
93
)
91
94
92
95
@classmethod
93
96
def _get_filter_instance (cls , filter_class , queryset , view ):
94
- qual_name = cls ._get_filter_cls_qual_name (filter_class , view )
97
+ qual_name = cls ._get_filter_cls_qual_name (view )
95
98
96
99
filter_instance = _FilterClassCache .CACHE .get (qual_name )
97
100
if filter_instance :
@@ -102,5 +105,5 @@ def _get_filter_instance(cls, filter_class, queryset, view):
102
105
return filter_instance
103
106
104
107
@staticmethod
105
- def _get_filter_cls_qual_name (filter_class , view ):
106
- return '{0}.{1}' .format (view .basename , filter_class .__name__ )
108
+ def _get_filter_cls_qual_name (view ):
109
+ return '{0}.{1}' .format (view .__class__ . __module__ , view . __class__ .__name__ )
0 commit comments