Skip to content

Commit 0702851

Browse files
committed
Improved caching for /courses endpoint
1 parent bfe33f8 commit 0702851

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/main/kotlin/ch/uzh/ifi/access/config/CacheConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CacheConfig {
3030
"PointsService.calculateAvgTaskPoints",
3131
"PointsService.calculateAssignmentMaxPoints",
3232
"CourseService.getStudents",
33+
"CourseService.calculateCoursePoints",
3334
)
3435
}
3536
}

src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,18 @@ class CourseService(
243243

244244
fun calculateCoursePoints(slug: String): Double {
245245
val userId = roleService.getUserId() ?: return 0.0
246+
return proxy.calculateCoursePoints(slug, userId)
247+
}
248+
249+
@Cacheable(value = ["CourseService.calculateCoursePoints"], key = "#slug + '-' + #userId")
250+
fun calculateCoursePoints(slug: String, userId: String): Double {
246251
return courseRepository.getTotalPoints(slug, userId) ?: 0.0
247252
}
248253

249254
fun getTeamMembers(memberIds: List<String>): Set<MemberOverview> {
250-
return memberIds.mapNotNull { courseRepository.getTeamMemberName(it) }.toSet()
255+
return setOf()
256+
// TODO: re-enable if needed
257+
//return memberIds.mapNotNull { courseRepository.getTeamMemberName(it) }.toSet()
251258
}
252259

253260
fun getTaskBySlug(courseSlug: String, assignmentSlug: String, taskSlug: String): Task {
@@ -309,6 +316,7 @@ class CourseService(
309316
evict = [
310317
CacheEvict(value = ["PointsService.getMaxPoints"], key = "#courseSlug"),
311318
CacheEvict(value = ["PointsService.calculateAssignmentMaxPoints"], allEntries = true),
319+
CacheEvict(value = ["CourseService.calculateCoursePoints"], allEntries = true),
312320
]
313321
)
314322
fun updateCourse(courseSlug: String): Course {

src/main/kotlin/ch/uzh/ifi/access/service/PointsService.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ class PointsService(
4242
)
4343
fun evictTaskPoints(taskId: Long, userId: String) {
4444
}
45+
46+
@Caching(
47+
evict = [
48+
CacheEvict("CourseService.calculateCoursePoints", key = "#courseSlug + '-' + #userId"),
49+
]
50+
)
51+
fun evictCoursePoints(courseSlug: String?, userId: String) {
52+
}
4553
}

src/main/kotlin/ch/uzh/ifi/access/service/SubmissionService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class SubmissionService(
113113
)
114114
}
115115
pointsService.evictTaskPoints(task.id!!, submissionDTO.userId!!)
116+
pointsService.evictCoursePoints(courseSlug, submissionDTO.userId!!)
116117
val evaluation =
117118
evaluationService.getEvaluation(task.id, submissionDTO.userId)
118119
?: task.createEvaluation(submissionDTO.userId)
@@ -145,6 +146,7 @@ class SubmissionService(
145146
submissionRepository.save(submission)
146147
evaluationRepository.save(evaluation)
147148
pointsService.evictTaskPoints(task.id!!, submissionDTO.userId!!)
149+
pointsService.evictCoursePoints(courseSlug, submissionDTO.userId!!)
148150
}
149151
return submission
150152
}

0 commit comments

Comments
 (0)