From d8b66742de19cc9cbe145a57a3d41b5ec6d6863a Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 26 Jun 2016 15:09:03 -0400 Subject: [PATCH] Populate cached models immediately upon startup --- src/main/java/net/frozenorb/apiv3/APIv3.java | 7 +++++++ src/main/java/net/frozenorb/apiv3/model/BannedAsn.java | 3 +-- .../java/net/frozenorb/apiv3/model/BannedCellCarrier.java | 3 +-- src/main/java/net/frozenorb/apiv3/model/Rank.java | 3 +-- src/main/java/net/frozenorb/apiv3/model/Server.java | 3 +-- src/main/java/net/frozenorb/apiv3/model/ServerGroup.java | 3 +-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index 6dee85e..b53458c 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -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() { diff --git a/src/main/java/net/frozenorb/apiv3/model/BannedAsn.java b/src/main/java/net/frozenorb/apiv3/model/BannedAsn.java index 7353d1b..3fdd9e7 100644 --- a/src/main/java/net/frozenorb/apiv3/model/BannedAsn.java +++ b/src/main/java/net/frozenorb/apiv3/model/BannedAsn.java @@ -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(); diff --git a/src/main/java/net/frozenorb/apiv3/model/BannedCellCarrier.java b/src/main/java/net/frozenorb/apiv3/model/BannedCellCarrier.java index 982b02b..28f3e22 100644 --- a/src/main/java/net/frozenorb/apiv3/model/BannedCellCarrier.java +++ b/src/main/java/net/frozenorb/apiv3/model/BannedCellCarrier.java @@ -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(); diff --git a/src/main/java/net/frozenorb/apiv3/model/Rank.java b/src/main/java/net/frozenorb/apiv3/model/Rank.java index 3ca4bb0..e882bae 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Rank.java +++ b/src/main/java/net/frozenorb/apiv3/model/Rank.java @@ -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(); diff --git a/src/main/java/net/frozenorb/apiv3/model/Server.java b/src/main/java/net/frozenorb/apiv3/model/Server.java index 6340425..8d65c14 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Server.java +++ b/src/main/java/net/frozenorb/apiv3/model/Server.java @@ -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(); diff --git a/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java b/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java index 61547f5..5f9b82f 100644 --- a/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java +++ b/src/main/java/net/frozenorb/apiv3/model/ServerGroup.java @@ -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();