Update dump cache immediately upon startup
This commit is contained in:
parent
c1017f9241
commit
043bc76cd3
@ -214,6 +214,7 @@ public final class APIv3 extends AbstractVerticle {
|
|||||||
Server.updateCache();
|
Server.updateCache();
|
||||||
ServerGroup.updateCache();
|
ServerGroup.updateCache();
|
||||||
EmailUtils.updateBannedEmailDomains();
|
EmailUtils.updateBannedEmailDomains();
|
||||||
|
GETDumpsType.updateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectMapper createMongoJacksonMapper() {
|
private ObjectMapper createMongoJacksonMapper() {
|
||||||
@ -244,7 +245,7 @@ public final class APIv3 extends AbstractVerticle {
|
|||||||
Router http = Router.router(vertx);
|
Router http = Router.router(vertx);
|
||||||
|
|
||||||
http.route().handler(LoggerHandler.create(LoggerFormat.TINY));
|
http.route().handler(LoggerHandler.create(LoggerFormat.TINY));
|
||||||
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5)));
|
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(7)));
|
||||||
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
|
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
|
||||||
http.route().handler(new ActorAttributeHandler());
|
http.route().handler(new ActorAttributeHandler());
|
||||||
http.route().handler(new MetricsHandler());
|
http.route().handler(new MetricsHandler());
|
||||||
|
@ -3,6 +3,7 @@ package net.frozenorb.apiv3.route;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import io.vertx.core.Handler;
|
import io.vertx.core.Handler;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.model.Grant;
|
import net.frozenorb.apiv3.model.Grant;
|
||||||
import net.frozenorb.apiv3.model.Punishment;
|
import net.frozenorb.apiv3.model.Punishment;
|
||||||
@ -11,67 +12,70 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public final class GETDumpsType implements Handler<RoutingContext> {
|
public final class GETDumpsType implements Handler<RoutingContext> {
|
||||||
|
|
||||||
private List<UUID> banCache = new LinkedList<>();
|
private static List<UUID> banCache = new LinkedList<>();
|
||||||
private List<UUID> blacklistCache = new LinkedList<>();
|
private static List<UUID> blacklistCache = new LinkedList<>();
|
||||||
private Map<String, List<UUID>> grantCache = new HashMap<>();
|
private static Map<String, List<UUID>> grantCache = new HashMap<>();
|
||||||
|
|
||||||
public GETDumpsType() {
|
static {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(5), (id) -> {
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(5), (id) -> updateCache());
|
||||||
Punishment.findByType(ImmutableSet.of(
|
}
|
||||||
Punishment.PunishmentType.BAN,
|
|
||||||
Punishment.PunishmentType.BLACKLIST
|
public static void updateCache() {
|
||||||
), (punishments, error) -> {
|
Punishment.findByType(ImmutableSet.of(
|
||||||
if (error != null) {
|
Punishment.PunishmentType.BAN,
|
||||||
error.printStackTrace();
|
Punishment.PunishmentType.BLACKLIST
|
||||||
return;
|
), (punishments, error) -> {
|
||||||
|
if (error != null) {
|
||||||
|
error.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UUID> banCache = new LinkedList<>();
|
||||||
|
List<UUID> blacklistCache = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Punishment punishment : punishments) {
|
||||||
|
if (!punishment.isActive()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UUID> banCache = new LinkedList<>();
|
if (punishment.getType() == Punishment.PunishmentType.BAN) {
|
||||||
List<UUID> blacklistCache = new LinkedList<>();
|
banCache.add(punishment.getUser());
|
||||||
|
} else if (punishment.getType() == Punishment.PunishmentType.BLACKLIST) {
|
||||||
|
blacklistCache.add(punishment.getUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Punishment punishment : punishments) {
|
GETDumpsType.banCache = banCache;
|
||||||
if (!punishment.isActive()) {
|
GETDumpsType.blacklistCache = blacklistCache;
|
||||||
continue;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (punishment.getType() == Punishment.PunishmentType.BAN) {
|
Grant.findAll((grants, error) -> {
|
||||||
banCache.add(punishment.getUser());
|
if (error != null) {
|
||||||
} else if (punishment.getType() == Punishment.PunishmentType.BLACKLIST) {
|
error.printStackTrace();
|
||||||
blacklistCache.add(punishment.getUser());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, List<UUID>> grantCache = new HashMap<>();
|
||||||
|
|
||||||
|
for (Grant grant : grants) {
|
||||||
|
if (!grant.isActive()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
GETDumpsType.this.banCache = banCache;
|
List<UUID> users = grantCache.get(grant.getRank());
|
||||||
GETDumpsType.this.blacklistCache = blacklistCache;
|
|
||||||
});
|
|
||||||
|
|
||||||
Grant.findAll((grants, error) -> {
|
if (users == null) {
|
||||||
if (error != null) {
|
users = new LinkedList<>();
|
||||||
error.printStackTrace();
|
grantCache.put(grant.getRank(), users);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<UUID>> grantCache = new HashMap<>();
|
users.add(grant.getUser());
|
||||||
|
}
|
||||||
|
|
||||||
for (Grant grant : grants) {
|
GETDumpsType.grantCache = grantCache;
|
||||||
if (!grant.isActive()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<UUID> users = grantCache.get(grant.getRank());
|
|
||||||
|
|
||||||
if (users == null) {
|
|
||||||
users = new LinkedList<>();
|
|
||||||
grantCache.put(grant.getRank(), users);
|
|
||||||
}
|
|
||||||
|
|
||||||
users.add(grant.getUser());
|
|
||||||
}
|
|
||||||
|
|
||||||
GETDumpsType.this.grantCache = grantCache;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user