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

Cache statistics data for a fixed amount of time

Real-time updates for global statistics are unnecessary and put a lot of
pressure on the database. Data is now cached for five minutes. The count
of online users is still updated in real-time.
parent 7fc43e99
Branches
Tags
No related merge requests found
Pipeline #3441 passed with stages
in 4 minutes and 58 seconds
......@@ -20,10 +20,12 @@ package de.thm.arsnova.services;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.Statistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
/**
* Performs all statistics related operations.
* Performs all statistics related operations. To reduce pressure on the database, data is cached for a fixed amount of
* time.
*/
@Service
public class StatisticsService implements IStatisticsService {
......@@ -34,9 +36,15 @@ public class StatisticsService implements IStatisticsService {
@Autowired
private IUserService userService;
private Statistics statistics = new Statistics();
@Scheduled(initialDelay = 0, fixedRate = 300000)
private void refreshStatistics() {
statistics = databaseDao.getStatistics();
}
@Override
public Statistics getStatistics() {
final Statistics statistics = databaseDao.getStatistics();
statistics.setActiveUsers(userService.loggedInUsers());
return statistics;
}
......
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