Stored plugin tabs in different cache

This commit is contained in:
Risto Lahtela 2021-02-12 09:50:40 +02:00
parent 36ff87abf2
commit 714b1a2b0c
3 changed files with 38 additions and 7 deletions

View File

@ -21,7 +21,7 @@ import com.djrapitops.plan.delivery.formatting.Formatters;
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
import com.djrapitops.plan.delivery.rendering.html.Contributors;
import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.delivery.webserver.cache.JSONStorage;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
import com.djrapitops.plan.identification.ServerInfo;
@ -54,6 +54,7 @@ public class NetworkPage implements Page {
private final Theme theme;
private final Locale locale;
private final ServerInfo serverInfo;
private final JSONStorage jsonStorage;
private final Formatters formatters;
NetworkPage(
@ -65,6 +66,7 @@ public class NetworkPage implements Page {
Theme theme,
Locale locale,
ServerInfo serverInfo,
JSONStorage jsonStorage,
Formatters formatters
) {
this.templateHtml = templateHtml;
@ -74,6 +76,7 @@ public class NetworkPage implements Page {
this.theme = theme;
this.locale = locale;
this.serverInfo = serverInfo;
this.jsonStorage = jsonStorage;
this.formatters = formatters;
}
@ -105,8 +108,17 @@ public class NetworkPage implements Page {
return new ServerPluginTabs(extensionData, formatters);
});
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID);
String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID);
String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> {
jsonStorage.invalidateOlder(navIdentifier, after);
return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav());
}).json;
String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> {
jsonStorage.invalidateOlder(tabIdentifier, after);
return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs());
}).json;
PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer();
pluginPlaceholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));

View File

@ -21,6 +21,7 @@ import com.djrapitops.plan.delivery.formatting.Formatters;
import com.djrapitops.plan.delivery.rendering.html.icon.Icon;
import com.djrapitops.plan.delivery.web.ResourceService;
import com.djrapitops.plan.delivery.web.resolver.exception.NotFoundException;
import com.djrapitops.plan.delivery.webserver.cache.JSONStorage;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery;
import com.djrapitops.plan.identification.Server;
@ -60,6 +61,7 @@ public class PageFactory {
private final Lazy<Theme> theme;
private final Lazy<DBSystem> dbSystem;
private final Lazy<ServerInfo> serverInfo;
private final Lazy<JSONStorage> jsonStorage;
private final Lazy<Formatters> formatters;
private final Lazy<DebugLogger> debugLogger;
private final Lazy<Timings> timings;
@ -74,6 +76,7 @@ public class PageFactory {
Lazy<Theme> theme,
Lazy<DBSystem> dbSystem,
Lazy<ServerInfo> serverInfo,
Lazy<JSONStorage> jsonStorage,
Lazy<Formatters> formatters,
Lazy<DebugLogger> debugLogger,
Lazy<Timings> timings,
@ -86,6 +89,7 @@ public class PageFactory {
this.theme = theme;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.jsonStorage = jsonStorage;
this.formatters = formatters;
this.debugLogger = debugLogger;
this.timings = timings;
@ -125,6 +129,7 @@ public class PageFactory {
versionChecker.get(),
dbSystem.get(),
serverInfo.get(),
jsonStorage.get(),
formatters.get()
);
}
@ -178,7 +183,9 @@ public class PageFactory {
dbSystem.get(),
versionChecker.get(),
config.get(), theme.get(), locale.get(),
serverInfo.get(), formatters.get());
serverInfo.get(),
jsonStorage.get(),
formatters.get());
}
public Page internalErrorPage(String message, Throwable error) {

View File

@ -22,7 +22,7 @@ import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
import com.djrapitops.plan.delivery.rendering.html.Contributors;
import com.djrapitops.plan.delivery.rendering.html.Html;
import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.delivery.webserver.cache.JSONStorage;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
import com.djrapitops.plan.identification.Server;
@ -54,6 +54,7 @@ public class ServerPage implements Page {
private final VersionChecker versionChecker;
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
private final JSONStorage jsonStorage;
private final Formatters formatters;
ServerPage(
@ -64,6 +65,7 @@ public class ServerPage implements Page {
VersionChecker versionChecker,
DBSystem dbSystem,
ServerInfo serverInfo,
JSONStorage jsonStorage,
Formatters formatters
) {
this.templateHtml = templateHtml;
@ -74,6 +76,7 @@ public class ServerPage implements Page {
this.versionChecker = versionChecker;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.jsonStorage = jsonStorage;
this.formatters = formatters;
}
@ -99,8 +102,17 @@ public class ServerPage implements Page {
return new ServerPluginTabs(extensionData, formatters);
});
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID);
String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID);
String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> {
jsonStorage.invalidateOlder(navIdentifier, after);
return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav());
}).json;
String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> {
jsonStorage.invalidateOlder(tabIdentifier, after);
return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs());
}).json;
PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer();
pluginPlaceholders.put("serverUUID", serverUUID.toString());