From 073772cf6b49b78b6295ca370dba0cf315e1bd38 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <code@dgerhardt.net> Date: Mon, 14 Nov 2016 16:25:56 +0100 Subject: [PATCH] Add config parameter for guest session cleanup The cleanup is now disabled by default and can be set up by uncommenting the configuration parameter `session.guest-session.cleanup-days`. --- .../de/thm/arsnova/services/SessionService.java | 14 +++++++++----- src/main/resources/arsnova.properties.example | 3 +++ src/test/resources/arsnova.properties.example | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index a9aa671c..8d7b93de 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -100,7 +100,6 @@ public class SessionService implements ISessionService, ApplicationEventPublishe } private static final long SESSION_INACTIVITY_CHECK_INTERVAL_MS = 30 * 60 * 1000L; - private static final long SESSION_INACTIVITY_THRESHOLD_MS = 90 * 24 * 60 * 60 * 1000L; @Autowired private IDatabaseDao databaseDao; @@ -120,6 +119,9 @@ public class SessionService implements ISessionService, ApplicationEventPublishe @Autowired private ImageUtils imageUtils; + @Value("${session.guest-session.cleanup-days:0}") + private int guestSessionInactivityThresholdDays; + @Value("${pp.logofilesize_b}") private int uploadFileSizeByte; @@ -129,10 +131,12 @@ public class SessionService implements ISessionService, ApplicationEventPublishe @Scheduled(fixedDelay = SESSION_INACTIVITY_CHECK_INTERVAL_MS) public void deleteInactiveSessions() { - LOGGER.info("Delete inactive sessions."); - long unixTime = System.currentTimeMillis(); - long lastActivityBefore = unixTime - SESSION_INACTIVITY_THRESHOLD_MS; - databaseDao.deleteInactiveGuestSessions(lastActivityBefore); + if (guestSessionInactivityThresholdDays > 0) { + LOGGER.info("Delete inactive sessions."); + long unixTime = System.currentTimeMillis(); + long lastActivityBefore = unixTime - guestSessionInactivityThresholdDays * 24 * 60 * 60 * 1000L; + databaseDao.deleteInactiveGuestSessions(lastActivityBefore); + } } public void setDatabaseDao(final IDatabaseDao newDatabaseDao) { diff --git a/src/main/resources/arsnova.properties.example b/src/main/resources/arsnova.properties.example index 294847ea..34fa9b0a 100644 --- a/src/main/resources/arsnova.properties.example +++ b/src/main/resources/arsnova.properties.example @@ -243,6 +243,9 @@ question.parse-answer-option-formatting=false # https://github.com/thm-projects/arsnova-mobile/tree/master/demo-sessions session.demo-id= +# Delete guest sessions automatically after X days of owner inactivity. +#session.guest-session.cleanup-days=180 + # Label underneath ARSnova logo ui.slogan=Audience Response System diff --git a/src/test/resources/arsnova.properties.example b/src/test/resources/arsnova.properties.example index 294847ea..34fa9b0a 100644 --- a/src/test/resources/arsnova.properties.example +++ b/src/test/resources/arsnova.properties.example @@ -243,6 +243,9 @@ question.parse-answer-option-formatting=false # https://github.com/thm-projects/arsnova-mobile/tree/master/demo-sessions session.demo-id= +# Delete guest sessions automatically after X days of owner inactivity. +#session.guest-session.cleanup-days=180 + # Label underneath ARSnova logo ui.slogan=Audience Response System -- GitLab