Skip to content
Snippets Groups Projects
Commit 11b6b4b0 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Delete inactive guest sessions

Lists of visited sessions for guest users which have not been active for
a fixed amount of time are now automatically deleted.
parent 073772cf
Branches
Tags
No related merge requests found
......@@ -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) {
......
......@@ -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);
......
......@@ -95,4 +95,6 @@ public interface ISessionService {
boolean flipFlashcards(String sessionkey, Boolean flip);
void deleteInactiveSessions();
void deleteInactiveVisitedSessionLists();
}
......@@ -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;
}
......
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment