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