Populate cached models immediately upon startup

This commit is contained in:
Colin McDonald 2016-06-26 15:09:03 -04:00
parent a4d00ca5b0
commit d8b66742de
6 changed files with 12 additions and 10 deletions

View File

@ -36,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.handler.ActorAttributeHandler;
import net.frozenorb.apiv3.handler.AuthorizationHandler;
import net.frozenorb.apiv3.handler.MetricsHandler;
import net.frozenorb.apiv3.model.*;
import net.frozenorb.apiv3.route.GETDumpsType;
import net.frozenorb.apiv3.route.GETWhoAmI;
import net.frozenorb.apiv3.route.auditLog.GETAuditLog;
@ -197,6 +198,12 @@ public final class APIv3 extends AbstractVerticle {
database.getCollection("userMeta").createIndexes(ImmutableList.of(
new IndexModel(new Document("user", 1).append("serverGroup", 1))
), (a, b) -> {});
BannedAsn.updateCache();
BannedCellCarrier.updateCache();
Rank.updateCache();
Server.updateCache();
ServerGroup.updateCache();
}
private ObjectMapper createMongoJacksonMapper() {

View File

@ -42,11 +42,10 @@ public final class BannedAsn {
}
static {
updateCache();
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
}
private static void updateCache() {
public static void updateCache() {
bannedAsnsCollection.find().into(new LinkedList<>(), (bannedAsns, error) -> {
if (error != null) {
error.printStackTrace();

View File

@ -43,11 +43,10 @@ public final class BannedCellCarrier {
}
static {
updateCache();
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
}
private static void updateCache() {
public static void updateCache() {
bannedCellCarriersCollection.find().into(new LinkedList<>(), (bannedCellCarriers, error) -> {
if (error != null) {
error.printStackTrace();

View File

@ -42,11 +42,10 @@ public final class Rank {
}
static {
updateCache();
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
}
private static void updateCache() {
public static void updateCache() {
ranksCollection.find().into(new LinkedList<>(), (ranks, error) -> {
if (error != null) {
error.printStackTrace();

View File

@ -45,12 +45,11 @@ public final class Server {
}
static {
updateCache();
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateTimedOutServers());
}
private static void updateCache() {
public static void updateCache() {
serversCollection.find().into(new LinkedList<>(), (servers, error) -> {
if (error != null) {
error.printStackTrace();

View File

@ -40,11 +40,10 @@ public final class ServerGroup {
}
static {
updateCache();
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
}
private static void updateCache() {
public static void updateCache() {
serverGroupsCollection.find().into(new LinkedList<>(), (serverGroups, error) -> {
if (error != null) {
error.printStackTrace();