fixed running exam cache

This commit is contained in:
anhefti 2020-10-05 16:53:59 +02:00
parent fcef3c08df
commit 2a5a243759
4 changed files with 17 additions and 20 deletions

View file

@ -24,11 +24,19 @@ public interface ExamDAO extends ActivatableEntityDAO<Exam, Exam>, BulkActionSup
/** Get a GrantEntity for the exam of specified id (PK)
* This is actually a Exam instance but with no course data loaded.
*
*
* @param id The id of the exam (PK)
* @return Result referring to the GrantEntity of the exam or to an error when happened */
Result<GrantEntity> examGrantEntityByPK(final Long id);
/** Get an Exam GrantEntity by a given ClientConnection id.
* This is actually a Exam instance but with no course data loaded.
*
* @param connectionId the connection identifier
* @return a Result containing the Exam GrantEntity by a given ClientConnection id or refer to an error if
* happened */
Result<GrantEntity> examGrantEntityByClientConnection(Long connectionId);
/** Get all active Exams for a given institution.
*
* @param institutionId the identifier of the institution
@ -56,12 +64,6 @@ public interface ExamDAO extends ActivatableEntityDAO<Exam, Exam>, BulkActionSup
key = "#exam.id")
Result<Exam> save(Exam exam);
/** Get an Exam by a given ClientConnection id.
*
* @param connectionId the connection identifier
* @return a Result containing the Exam by a given ClientConnection id or refer to an error if happened */
Result<Exam> byClientConnection(Long connectionId);
/** Use this to get identifiers of all exams in a specified state for a specified institution.
*
* @param institutionId the institution identifier. May be null for all institutions

View file

@ -92,12 +92,11 @@ public class ExamDAOImpl implements ExamDAO {
@Override
@Transactional(readOnly = true)
public Result<Exam> byClientConnection(final Long connectionId) {
public Result<GrantEntity> examGrantEntityByClientConnection(final Long connectionId) {
return Result.tryCatch(() -> this.clientConnectionRecordMapper
.selectByPrimaryKey(connectionId))
.flatMap(ccRecord -> recordById(ccRecord.getExamId()))
.flatMap(this::toDomainModelCached)
.onError(TransactionHandler::rollback);
.map(record -> toDomainModel(record, null).getOrThrow());
}
@Override
@ -671,14 +670,6 @@ public class ExamDAOImpl implements ExamDAO {
});
}
private Result<Exam> toDomainModelCached(final ExamRecord record) {
return Result.tryCatch(() -> this.lmsAPIService
.getLmsAPITemplate(record.getLmsSetupId())
.getOrThrow())
.flatMap(template -> template.getQuizFromCache(record.getExternalId()))
.flatMap(quizData -> this.toDomainModel(record, quizData));
}
private Result<Exam> toDomainModel(final ExamRecord record) {
return toDomainModel(
record.getLmsSetupId(),

View file

@ -239,9 +239,13 @@ public class ExamSessionServiceImpl implements ExamSessionService {
.putIfAbsent(Exam.FILTER_ATTR_ACTIVE, Constants.TRUE_STRING)
.putIfAbsent(Exam.FILTER_ATTR_STATUS, ExamStatus.RUNNING.name());
// NOTE: we evict the exam from the cache (if present) to ensure user is seeing always the current state of the Exam
return this.examDAO.allMatching(filterMap, predicate)
.map(col -> col.stream()
.map(exam -> this.examSessionCacheService.getRunningExam(exam.id))
.map(exam -> {
this.examSessionCacheService.evict(exam);
return this.examSessionCacheService.getRunningExam(exam.id);
})
.filter(Objects::nonNull)
.collect(Collectors.toList()));
}

View file

@ -126,7 +126,7 @@ public class ClientEventController extends ReadonlyEntityController<ClientEvent,
@Override
protected GrantEntity toGrantEntity(final ClientEvent entity) {
return this.examDAO
.byClientConnection(entity.connectionId)
.examGrantEntityByClientConnection(entity.connectionId)
.get();
}