@@ -245,34 +245,50 @@ public final Response getConcept(@Context final Request request, @Context final
245
245
if (null == conceptId || conceptId .isEmpty ()) {
246
246
return new SegueErrorResponse (Status .BAD_REQUEST , "You must provide a valid concept id." ).toResponse ();
247
247
}
248
-
249
- // Calculate the ETag on current live version of the content:
250
- EntityTag etag = new EntityTag (
251
- String .valueOf (this .contentManager .getCurrentContentSHA ().hashCode () + conceptId .hashCode ())
252
- );
253
- Response cachedResponse = generateCachedResponse (request , etag );
254
- if (cachedResponse != null ) {
255
- return cachedResponse ;
256
- }
257
-
258
248
try {
249
+ AbstractSegueUserDTO user = userManager .getCurrentUser (servletRequest );
250
+
259
251
ContentDTO contentDTO = contentManager .getContentById (conceptId , true );
260
252
if (contentDTO instanceof IsaacConceptPageDTO ) {
261
253
SeguePageDTO content = (SeguePageDTO ) contentDTO ;
262
- // Do we want to use the user's actual question attempts here? We did not previously.
263
- augmentContentWithRelatedContent (content , Collections .emptyMap ());
264
254
255
+ // Load attempts at related questions:
256
+ Map <String , ? extends Map <String , ? extends List <? extends LightweightQuestionValidationResponse >>> relatedQuestionAttempts ;
257
+ List <String > relatedQuestionIds = new ArrayList <>(getRelatedContentIds (content ));
258
+ if (user instanceof AnonymousUserDTO ) {
259
+ // For anon users, must load all attempts:
260
+ relatedQuestionAttempts = questionManager .getQuestionAttemptsByUser (user );
261
+ } else {
262
+ // For registered users, can load only relevant lightweight attempts:
263
+ RegisteredUserDTO registeredUser = (RegisteredUserDTO ) user ;
264
+ relatedQuestionAttempts = questionManager .getMatchingLightweightQuestionAttempts (
265
+ registeredUser , relatedQuestionIds
266
+ );
267
+ }
268
+
269
+ // Check the cache status:
270
+ EntityTag etag = new EntityTag (String .valueOf (
271
+ this .contentManager .getCurrentContentSHA ().hashCode ()
272
+ + conceptId .hashCode ()
273
+ + relatedQuestionAttempts .hashCode ()
274
+ ));
275
+ Response cachedResponse = generateCachedResponse (request , etag );
276
+ if (cachedResponse != null ) {
277
+ return cachedResponse ;
278
+ }
279
+
280
+ // Augment related content with question attempts:
281
+ augmentContentWithRelatedContent (content , relatedQuestionAttempts );
282
+
283
+ // Log the request:
265
284
ImmutableMap <String , String > logEntry = new ImmutableMap .Builder <String , String >()
266
285
.put (CONCEPT_ID_LOG_FIELDNAME , conceptId )
267
286
.put (CONTENT_VERSION_FIELDNAME , this .contentManager .getCurrentContentSHA ())
268
287
.build ();
269
-
270
- // the request log
271
- getLogManager ().logEvent (userManager .getCurrentUser (servletRequest ), servletRequest ,
272
- IsaacServerLogType .VIEW_CONCEPT , logEntry );
288
+ getLogManager ().logEvent (user , servletRequest , IsaacServerLogType .VIEW_CONCEPT , logEntry );
273
289
274
290
return Response .ok (content )
275
- .cacheControl (getCacheControl (NUMBER_SECONDS_IN_ONE_HOUR , true ))
291
+ .cacheControl (getCacheControl (NEVER_CACHE_WITHOUT_ETAG_CHECK , false ))
276
292
.tag (etag )
277
293
.build ();
278
294
} else {
0 commit comments