mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
parent
5468a22c50
commit
79fbf245d9
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.gathering.domain.TPS;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.identification.ServerUUID;
|
||||
@ -46,6 +47,19 @@ public class ServerUptimeCalculator {
|
||||
if (serverUUID.equals(serverInfo.getServerUUID())) {
|
||||
return Optional.of(System.currentTimeMillis() - PlanSystem.getServerEnableTime());
|
||||
} else {
|
||||
return getServerUptimeMillisFromDatabase(serverUUID);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Long> getServerUptimeMillisFromDatabase(ServerUUID serverUUID) {
|
||||
try {
|
||||
return tryToGetServerUptimeMillisFromDatabase(serverUUID);
|
||||
} catch (DBOpException windowFunctionsNotSupported) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Long> tryToGetServerUptimeMillisFromDatabase(ServerUUID serverUUID) {
|
||||
long dataGapThreshold = TimeUnit.MINUTES.toMillis(3);
|
||||
Database database = dbSystem.getDatabase();
|
||||
Optional<Long> latestDataDate = database.query(TPSQueries.fetchLatestTPSEntryForServer(serverUUID)).map(TPS::getDate);
|
||||
@ -61,6 +75,5 @@ public class ServerUptimeCalculator {
|
||||
|
||||
return Optional.of(System.currentTimeMillis() - dataBlockStartDate.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user