14
14
15
15
16
16
from api .serializers import AlbumAutoListSerializer
17
+ from api .serializers import AlbumPersonListSerializer
18
+ from api .serializers import AlbumDateListSerializer
17
19
18
20
19
21
from api .face_classify import train_faces , cluster_faces
43
45
PaginationKeyBit
44
46
)
45
47
48
+ # CACHE_TTL = 60 * 60 * 24 # 1 day
49
+ CACHE_TTL = 60 * 60 * 24 # 1 min
50
+
46
51
#caching stuff straight out of https://chibisov.github.io/drf-extensions/docs/#caching
47
52
class UpdatedAtKeyBit (KeyBitBase ):
48
53
def get_data (self , ** kwargs ):
@@ -78,11 +83,11 @@ class PhotoViewSet(viewsets.ModelViewSet):
78
83
serializer_class = PhotoSerializer
79
84
pagination_class = StandardResultsSetPagination
80
85
81
- @cache_response (key_func = CustomObjectKeyConstructor ())
86
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
82
87
def retrieve (self , * args , ** kwargs ):
83
88
return super (PhotoViewSet , self ).retrieve (* args , ** kwargs )
84
89
85
- @cache_response (key_func = CustomListKeyConstructor ())
90
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
86
91
def list (self , * args , ** kwargs ):
87
92
return super (PhotoViewSet , self ).list (* args , ** kwargs )
88
93
@@ -91,11 +96,11 @@ class FaceViewSet(viewsets.ModelViewSet):
91
96
serializer_class = FaceSerializer
92
97
pagination_class = StandardResultsSetPagination
93
98
94
- @cache_response (key_func = CustomObjectKeyConstructor ())
99
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
95
100
def retrieve (self , * args , ** kwargs ):
96
101
return super (FaceViewSet , self ).retrieve (* args , ** kwargs )
97
102
98
- @cache_response (key_func = CustomListKeyConstructor ())
103
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
99
104
def list (self , * args , ** kwargs ):
100
105
return super (FaceViewSet , self ).list (* args , ** kwargs )
101
106
@@ -106,11 +111,11 @@ class FaceInferredViewSet(viewsets.ModelViewSet):
106
111
serializer_class = FaceSerializer
107
112
pagination_class = StandardResultsSetPagination
108
113
109
- @cache_response (key_func = CustomObjectKeyConstructor ())
114
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
110
115
def retrieve (self , * args , ** kwargs ):
111
116
return super (FaceInferredViewSet , self ).retrieve (* args , ** kwargs )
112
117
113
- @cache_response (key_func = CustomListKeyConstructor ())
118
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
114
119
def list (self , * args , ** kwargs ):
115
120
return super (FaceInferredViewSet , self ).list (* args , ** kwargs )
116
121
@@ -120,11 +125,11 @@ class FaceLabeledViewSet(viewsets.ModelViewSet):
120
125
serializer_class = FaceSerializer
121
126
pagination_class = StandardResultsSetPagination
122
127
123
- @cache_response (key_func = CustomObjectKeyConstructor ())
128
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
124
129
def retrieve (self , * args , ** kwargs ):
125
130
return super (FaceLabeledViewSet , self ).retrieve (* args , ** kwargs )
126
131
127
- @cache_response (key_func = CustomListKeyConstructor ())
132
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
128
133
def list (self , * args , ** kwargs ):
129
134
return super (FaceLabeledViewSet , self ).list (* args , ** kwargs )
130
135
@@ -135,74 +140,112 @@ class PersonViewSet(viewsets.ModelViewSet):
135
140
serializer_class = PersonSerializer
136
141
pagination_class = StandardResultsSetPagination
137
142
138
- @cache_response (key_func = CustomObjectKeyConstructor ())
143
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
139
144
def retrieve (self , * args , ** kwargs ):
140
145
return super (PersonViewSet , self ).retrieve (* args , ** kwargs )
141
146
142
- @cache_response (key_func = CustomListKeyConstructor ())
147
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
143
148
def list (self , * args , ** kwargs ):
144
149
return super (PersonViewSet , self ).list (* args , ** kwargs )
145
150
146
151
152
+
153
+
154
+
155
+
147
156
class AlbumAutoViewSet (viewsets .ModelViewSet ):
148
157
queryset = AlbumAuto .objects .all ().order_by ('-timestamp' )
149
158
serializer_class = AlbumAutoSerializer
150
159
pagination_class = StandardResultsSetPagination
151
160
152
- @cache_response (key_func = CustomObjectKeyConstructor ())
161
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
153
162
def retrieve (self , * args , ** kwargs ):
154
163
return super (AlbumAutoViewSet , self ).retrieve (* args , ** kwargs )
155
164
156
- @cache_response (key_func = CustomListKeyConstructor ())
165
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
157
166
def list (self , * args , ** kwargs ):
158
167
return super (AlbumAutoViewSet , self ).list (* args , ** kwargs )
159
168
160
-
161
-
162
169
class AlbumAutoListViewSet (viewsets .ModelViewSet ):
163
170
queryset = AlbumAuto .objects .all ().order_by ('-timestamp' )
164
171
serializer_class = AlbumAutoListSerializer
165
172
pagination_class = StandardResultsSetPagination
166
173
167
- @cache_response (key_func = CustomObjectKeyConstructor ())
174
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
168
175
def retrieve (self , * args , ** kwargs ):
169
176
return super (AlbumAutoListViewSet , self ).retrieve (* args , ** kwargs )
170
177
171
- @cache_response (key_func = CustomListKeyConstructor ())
178
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
172
179
def list (self , * args , ** kwargs ):
173
180
return super (AlbumAutoListViewSet , self ).list (* args , ** kwargs )
174
181
175
182
176
183
184
+
185
+
186
+
187
+
177
188
class AlbumPersonViewSet (viewsets .ModelViewSet ):
178
189
queryset = Person .objects .all ().order_by ('name' )
179
190
serializer_class = AlbumPersonSerializer
180
191
pagination_class = StandardResultsSetPagination
181
192
182
- @cache_response (key_func = CustomObjectKeyConstructor ())
193
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
183
194
def retrieve (self , * args , ** kwargs ):
184
195
return super (AlbumPersonViewSet , self ).retrieve (* args , ** kwargs )
185
196
186
- @cache_response (key_func = CustomListKeyConstructor ())
197
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
187
198
def list (self , * args , ** kwargs ):
188
199
return super (AlbumPersonViewSet , self ).list (* args , ** kwargs )
189
200
190
201
202
+ class AlbumPersonListViewSet (viewsets .ModelViewSet ):
203
+ queryset = Person .objects .all ().order_by ('name' )
204
+ serializer_class = AlbumPersonListSerializer
205
+ pagination_class = StandardResultsSetPagination
206
+
207
+ @cache_response (CACHE_TTL ,key_func = CustomObjectKeyConstructor ())
208
+ def retrieve (self , * args , ** kwargs ):
209
+ return super (AlbumPersonListViewSet , self ).retrieve (* args , ** kwargs )
210
+
211
+ @cache_response (CACHE_TTL ,key_func = CustomListKeyConstructor ())
212
+ def list (self , * args , ** kwargs ):
213
+ return super (AlbumPersonListViewSet , self ).list (* args , ** kwargs )
214
+
215
+
216
+
217
+
191
218
192
219
193
220
class AlbumDateViewSet (viewsets .ModelViewSet ):
194
221
queryset = AlbumDate .objects .all ().order_by ('-date' )
195
222
serializer_class = AlbumDateSerializer
196
223
pagination_class = StandardResultsSetPagination
197
224
198
- @cache_response (key_func = CustomObjectKeyConstructor ())
225
+ @cache_response (CACHE_TTL , key_func = CustomObjectKeyConstructor ())
199
226
def retrieve (self , * args , ** kwargs ):
200
227
return super (AlbumDateViewSet , self ).retrieve (* args , ** kwargs )
201
228
202
- @cache_response (key_func = CustomListKeyConstructor ())
229
+ @cache_response (CACHE_TTL , key_func = CustomListKeyConstructor ())
203
230
def list (self , * args , ** kwargs ):
204
231
return super (AlbumDateViewSet , self ).list (* args , ** kwargs )
205
232
233
+
234
+ class AlbumDateListViewSet (viewsets .ModelViewSet ):
235
+ queryset = AlbumDate .objects .all ().order_by ('-date' )
236
+ serializer_class = AlbumDateListSerializer
237
+ pagination_class = StandardResultsSetPagination
238
+
239
+ @cache_response (CACHE_TTL ,key_func = CustomObjectKeyConstructor ())
240
+ def retrieve (self , * args , ** kwargs ):
241
+ return super (AlbumDateListViewSet , self ).retrieve (* args , ** kwargs )
242
+
243
+ @cache_response (CACHE_TTL ,key_func = CustomListKeyConstructor ())
244
+ def list (self , * args , ** kwargs ):
245
+ return super (AlbumDateListViewSet , self ).list (* args , ** kwargs )
246
+
247
+
248
+
206
249
# API Views
207
250
208
251
class FaceToLabelView (APIView ):
0 commit comments