diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index 6284823036cb4f9e2f9ee8a706d7e4854c38c038..e3f87fd89aae34d90a6421adf3ea10659d1d664e 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -1703,6 +1703,36 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return false; } + @Override + public boolean deleteInactiveGuestVisitedSessionLists(long lastActivityBefore) { + try { + NovaView view = new NovaView("logged_in/by_last_activity_for_guests"); + view.setEndKey(lastActivityBefore); + List<Document> results = this.getDatabase().view(view).getResults(); + + final List<Document> newDocs = new ArrayList<Document>(); + for (Document oldDoc : results) { + final Document newDoc = new Document(); + newDoc.setId(oldDoc.getId()); + newDoc.setRev(oldDoc.getJSONObject("value").getString("_rev")); + newDoc.put("_deleted", true); + newDocs.add(newDoc); + LOGGER.debug("Marked logged_in document {} for deletion.", oldDoc.getId()); + } + + if (newDocs.size() > 0) { + getDatabase().bulkSaveDocuments(newDocs.toArray(new Document[newDocs.size()])); + LOGGER.info("Deleted {} visited session lists of inactive users.", newDocs.size()); + } + + return true; + } catch (IOException e) { + LOGGER.error("Could not delete visited session lists of inactive users."); + } + + return false; + } + @Cacheable("lecturequestions") @Override public List<Question> getLectureQuestionsForUsers(final Session session) { diff --git a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java index c8ccf8c3c3aa95c3eefd7091cf591be2a9380252..a7372b085f4883efca0df69ee15d3e4746994f00 100644 --- a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java +++ b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java @@ -148,6 +148,8 @@ public interface IDatabaseDao { boolean deleteInactiveGuestSessions(long lastActivityBefore); + boolean deleteInactiveGuestVisitedSessionLists(long lastActivityBefore); + List<Question> getLectureQuestionsForUsers(Session session); List<Question> getLectureQuestionsForTeachers(Session session); diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java index 7b6c742068adb955a7e43845ac1ab90a88f7227d..5c20b4c3ecdf3d0e41dcbd693ccda4d2c692e500 100644 --- a/src/main/java/de/thm/arsnova/services/ISessionService.java +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -95,4 +95,6 @@ public interface ISessionService { boolean flipFlashcards(String sessionkey, Boolean flip); void deleteInactiveSessions(); + + void deleteInactiveVisitedSessionLists(); } diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index 8d7b93de902d8b30c6ba329bd9f8d851d49427e7..8ac0aa34702e610b509f910e7ea663e1c7f9dded 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -139,6 +139,16 @@ public class SessionService implements ISessionService, ApplicationEventPublishe } } + @Scheduled(fixedDelay = SESSION_INACTIVITY_CHECK_INTERVAL_MS) + public void deleteInactiveVisitedSessionLists() { + if (guestSessionInactivityThresholdDays > 0) { + LOGGER.info("Delete lists of visited session for inactive users."); + long unixTime = System.currentTimeMillis(); + long lastActivityBefore = unixTime - guestSessionInactivityThresholdDays * 24 * 60 * 60 * 1000L; + databaseDao.deleteInactiveGuestVisitedSessionLists(lastActivityBefore); + } + } + public void setDatabaseDao(final IDatabaseDao newDatabaseDao) { databaseDao = newDatabaseDao; } diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java index 1a1c4c6688daa283a8b6f210d4309a6e1d5b69c7..acfabb8c7905fb8d16739f26bf4103622d1a61e6 100644 --- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java +++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java @@ -351,6 +351,12 @@ public class StubDatabaseDao implements IDatabaseDao { return false; } + @Override + public boolean deleteInactiveGuestVisitedSessionLists(long lastActivityBefore) { + // TODO Auto-generated method stub + return false; + } + @Override public void deleteAllQuestionsWithAnswers(Session session) { // TODO Auto-generated method stub