Skip to content

Commit

Permalink
CSCEXAM-1375 Make examination start delay as milliseconds for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
lupari committed Jan 23, 2025
1 parent 6159be2 commit 07b31b5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/models/enrolment/ExamEnrolment.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Entity
public class ExamEnrolment extends GeneratedIdentityModel implements Comparable<ExamEnrolment> {

private static final int DELAY_MAX = 30;
private static final int DELAY_MAX = 30 * 1000;

@ManyToOne
@JsonManagedReference
Expand Down
13 changes: 4 additions & 9 deletions app/repository/EnrolmentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,6 @@ private void handleUpcomingEnrolment(
if (
enrolment.getExam() != null && enrolment.getExam().getImplementation() == Exam.Implementation.AQUARIUM
) {
// If user is on a correct aquarium machine then always set a header
headers.put(
"x-exam-aquarium-login",
String.format("%s:::%d", getExamHash(enrolment), enrolment.getId())
);
// Aquarium exam, don't set headers unless it starts in 5 minutes
DateTime threshold = DateTime.now().plusMinutes(5);
DateTime start = dateTimeHandler.normalize(
Expand Down Expand Up @@ -327,22 +322,22 @@ private boolean isInsideBounds(ExamEnrolment ee, int minutesToFuture) {
int delay = ee.getDelay();
return (
(reservation != null &&
reservation.getStartAt().plusSeconds(delay).isBefore(latest) &&
reservation.getStartAt().plusMillis(delay).isBefore(latest) &&
reservation.getEndAt().isAfter(earliest)) ||
(event != null &&
event.getStart().plusSeconds(delay).isBefore(latest) &&
event.getStart().plusMillis(delay).isBefore(latest) &&
event.getStart().plusMinutes(ee.getExam().getDuration()).isAfter(earliest))
);
}

private DateTime getStartTime(ExamEnrolment enrolment) {
return enrolment.getReservation() != null
? enrolment.getReservation().getStartAt().plusSeconds(enrolment.getDelay())
? enrolment.getReservation().getStartAt().plusMillis(enrolment.getDelay())
: enrolment
.getExaminationEventConfiguration()
.getExaminationEvent()
.getStart()
.plusSeconds(enrolment.getDelay());
.plusMillis(enrolment.getDelay());
}

private Optional<ExamEnrolment> getNextEnrolment(Long userId, int minutesToFuture) {
Expand Down
9 changes: 9 additions & 0 deletions conf/evolutions/default/136.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- SPDX-FileCopyrightText: 2024 The members of the EXAM Consortium
--
-- SPDX-License-Identifier: EUPL-1.2

# --- !Ups
UPDATE exam_enrolment SET delay = delay * 1000;

# --- !Downs
UPDATE exam_enrolment SET delay = delay / 1000;
6 changes: 3 additions & 3 deletions ui/src/app/enrolment/waiting-room/waiting-room.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { MathJaxDirective } from 'src/app/shared/math/math-jax.directive';
import { CourseCodeComponent } from 'src/app/shared/miscellaneous/course-code.component';
import { TeacherListComponent } from 'src/app/shared/user/teacher-list.component';

export type WaitingReservation = Reservation & { occasion: { startAt: string; endAt: string } };
export type WaitingEnrolment = Omit<ExamEnrolment, 'reservation'> & {
type WaitingReservation = Reservation & { occasion: { startAt: string; endAt: string } };
type WaitingEnrolment = Omit<ExamEnrolment, 'reservation'> & {
reservation: WaitingReservation;
};

Expand Down Expand Up @@ -102,7 +102,7 @@ export class WaitingRoomComponent implements OnInit, OnDestroy {
private startScheduled = () => {
window.clearTimeout(this.startTimerId);
const offset = Math.ceil(
DateTime.fromJSDate(this.getStart()).plus({ seconds: this.enrolment.delay }).toSeconds() -
DateTime.fromJSDate(this.getStart()).plus({ milliseconds: this.enrolment.delay }).toSeconds() -
DateTime.now().toSeconds(),
);
this.delayTimerId = window.setTimeout(this.Session.checkSession, Math.max(0, offset * 1000));
Expand Down

0 comments on commit 07b31b5

Please sign in to comment.