mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-20 07:02:21 +01:00
Cached Extension Tab results
This commit is contained in:
parent
d2581df3f6
commit
8f5e46e9ad
@ -16,8 +16,11 @@
|
||||
*/
|
||||
package com.djrapitops.plan.delivery.rendering.pages;
|
||||
|
||||
import com.djrapitops.plan.delivery.domain.container.CachingSupplier;
|
||||
import com.djrapitops.plan.delivery.formatting.Formatters;
|
||||
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.exceptions.ParseException;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
|
||||
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
|
||||
@ -89,12 +92,13 @@ public class NetworkPage implements Page {
|
||||
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
||||
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
||||
|
||||
List<ExtensionData> extensionData = dbSystem.getDatabase()
|
||||
.query(new ExtensionServerDataQuery(serverUUID));
|
||||
ServerPluginTabs pluginTabs = new ServerPluginTabs(extensionData, formatters);
|
||||
CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
|
||||
List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
|
||||
return new ServerPluginTabs(extensionData, formatters);
|
||||
});
|
||||
|
||||
String nav = pluginTabs.getNav();
|
||||
String tabs = pluginTabs.getTabs();
|
||||
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
|
||||
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getTabs());
|
||||
|
||||
placeholders.put("navPluginsTabs", nav);
|
||||
placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}"));
|
||||
|
@ -16,12 +16,15 @@
|
||||
*/
|
||||
package com.djrapitops.plan.delivery.rendering.pages;
|
||||
|
||||
import com.djrapitops.plan.delivery.domain.container.CachingSupplier;
|
||||
import com.djrapitops.plan.delivery.domain.container.DataContainer;
|
||||
import com.djrapitops.plan.delivery.domain.container.RawDataContainer;
|
||||
import com.djrapitops.plan.delivery.domain.keys.AnalysisKeys;
|
||||
import com.djrapitops.plan.delivery.formatting.Formatters;
|
||||
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
||||
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.exceptions.ParseException;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
|
||||
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
|
||||
@ -37,6 +40,7 @@ import com.djrapitops.plan.version.VersionCheckSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.delivery.domain.keys.AnalysisKeys.*;
|
||||
|
||||
@ -80,7 +84,8 @@ public class ServerPage implements Page {
|
||||
public String toHtml() throws ParseException {
|
||||
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||
|
||||
placeholders.put("serverUUID", server.getUuid().toString());
|
||||
UUID serverUUID = server.getUuid();
|
||||
placeholders.put("serverUUID", serverUUID.toString());
|
||||
placeholders.put("serverName", server.getIdentifiableName());
|
||||
placeholders.put("serverDisplayName", server.getName());
|
||||
|
||||
@ -123,12 +128,13 @@ public class ServerPage implements Page {
|
||||
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
||||
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
||||
|
||||
List<ExtensionData> extensionData = dbSystem.getDatabase()
|
||||
.query(new ExtensionServerDataQuery(server.getUuid()));
|
||||
ServerPluginTabs pluginTabs = new ServerPluginTabs(extensionData, formatters);
|
||||
CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
|
||||
List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
|
||||
return new ServerPluginTabs(extensionData, formatters);
|
||||
});
|
||||
|
||||
String nav = pluginTabs.getNav();
|
||||
String tabs = pluginTabs.getTabs();
|
||||
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
|
||||
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getTabs());
|
||||
|
||||
placeholders.put("navPluginsTabs", nav);
|
||||
placeholders.put("tabsPlugins", tabs);
|
||||
|
@ -45,6 +45,8 @@ public enum DataID {
|
||||
PVP_PVE,
|
||||
PLAYERBASE_OVERVIEW,
|
||||
PERFORMANCE_OVERVIEW,
|
||||
EXTENSION_NAV,
|
||||
EXTENSION_TABS
|
||||
;
|
||||
|
||||
public String of(UUID serverUUID) {
|
||||
|
@ -56,6 +56,17 @@ public class JSONCache {
|
||||
return new JSONResponse(found);
|
||||
}
|
||||
|
||||
public static String getOrCacheString(DataID dataID, UUID serverUUID, Supplier<String> stringSupplier) {
|
||||
String identifier = dataID.of(serverUUID);
|
||||
String found = cache.getIfPresent(identifier);
|
||||
if (found == null) {
|
||||
String result = stringSupplier.get();
|
||||
cache.put(identifier, result);
|
||||
return result;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public static Response getOrCache(DataID dataID, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||
return getOrCache(dataID.name(), jsonResponseSupplier);
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
package com.djrapitops.plan.extension;
|
||||
|
||||
import com.djrapitops.plan.DebugChannels;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.exceptions.DataExtensionMethodCallException;
|
||||
import com.djrapitops.plan.extension.implementation.CallerImplementation;
|
||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||
@ -161,9 +163,9 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
// Try again
|
||||
updatePlayerValues(gatherer, playerUUID, playerName, event);
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError unexpectedError) {
|
||||
logger.warn("Encountered unexpected error with " + gatherer.getPluginName() + " Extension (please report this): " + unexpectedError +
|
||||
logger.warn("Encountered unexpected error with " + gatherer.getPluginName() + " Extension: " + unexpectedError +
|
||||
" (but failed safely) when updating value for '" + playerName +
|
||||
"', stack trace to follow:");
|
||||
"', stack trace to follow (please report this):");
|
||||
errorHandler.log(L.WARN, gatherer.getClass(), unexpectedError);
|
||||
}
|
||||
}
|
||||
@ -171,10 +173,10 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
private void logFailure(String playerName, DataExtensionMethodCallException methodCallFailed) {
|
||||
Throwable cause = methodCallFailed.getCause();
|
||||
String causeName = cause.getClass().getSimpleName();
|
||||
logger.warn("Encountered " + causeName + " with " + methodCallFailed.getPluginName() + " Extension (please report this)" +
|
||||
logger.warn("Encountered " + causeName + " with " + methodCallFailed.getPluginName() + " Extension" +
|
||||
" (failed safely) when updating value for '" + playerName +
|
||||
"', the method was disabled temporarily (won't be called until next Plan reload)" +
|
||||
", stack trace to follow:");
|
||||
", stack trace to follow (please report this):");
|
||||
errorHandler.log(L.WARN, getClass(), cause);
|
||||
}
|
||||
|
||||
@ -182,6 +184,9 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
for (ProviderValueGatherer gatherer : extensionGatherers.values()) {
|
||||
updateServerValues(gatherer, event);
|
||||
}
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
JSONCache.invalidate(DataID.EXTENSION_NAV, serverUUID);
|
||||
JSONCache.invalidate(DataID.EXTENSION_TABS, serverUUID);
|
||||
}
|
||||
|
||||
public void updateServerValues(ProviderValueGatherer gatherer, CallEvents event) {
|
||||
@ -200,8 +205,8 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
// Try again
|
||||
updateServerValues(gatherer, event);
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError unexpectedError) {
|
||||
logger.warn("Encountered unexpected error with " + gatherer.getPluginName() + " Extension (please report this): " + unexpectedError +
|
||||
" (failed safely) when updating value for server, stack trace to follow:");
|
||||
logger.warn("Encountered unexpected error with " + gatherer.getPluginName() + " Extension: " + unexpectedError +
|
||||
" (failed safely) when updating value for server, stack trace to follow (please report this):");
|
||||
errorHandler.log(L.WARN, gatherer.getClass(), unexpectedError);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user