mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 11:08:08 +01:00
Cache and refreshable player tables
This commit is contained in:
parent
714b1a2b0c
commit
dbe3b849c4
@ -22,6 +22,7 @@ import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.ProxySettings;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.theme.Theme;
|
||||
import com.djrapitops.plan.version.VersionChecker;
|
||||
@ -60,6 +61,7 @@ public class PlayersPage implements Page {
|
||||
public String toHtml() {
|
||||
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||
|
||||
placeholders.put("refreshBarrier", config.get(WebserverSettings.REDUCED_REFRESH_BARRIER));
|
||||
placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
|
||||
placeholders.put("updateModal", versionChecker.getUpdateModal());
|
||||
placeholders.put("contributors", Contributors.generateContributorHtml());
|
||||
|
@ -17,12 +17,14 @@
|
||||
package com.djrapitops.plan.delivery.webserver.resolver.json;
|
||||
|
||||
import com.djrapitops.plan.delivery.rendering.json.JSONFactory;
|
||||
import com.djrapitops.plan.delivery.web.resolver.MimeType;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Resolver;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Response;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.WebUser;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.AsyncJSONResolverService;
|
||||
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.identification.Identifiers;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -39,14 +41,17 @@ import java.util.UUID;
|
||||
public class PlayersTableJSONResolver implements Resolver {
|
||||
|
||||
private final Identifiers identifiers;
|
||||
private final AsyncJSONResolverService jsonResolverService;
|
||||
private final JSONFactory jsonFactory;
|
||||
|
||||
@Inject
|
||||
public PlayersTableJSONResolver(
|
||||
Identifiers identifiers,
|
||||
AsyncJSONResolverService jsonResolverService,
|
||||
JSONFactory jsonFactory
|
||||
) {
|
||||
this.identifiers = identifiers;
|
||||
this.jsonResolverService = jsonResolverService;
|
||||
this.jsonFactory = jsonFactory;
|
||||
}
|
||||
|
||||
@ -66,11 +71,22 @@ public class PlayersTableJSONResolver implements Resolver {
|
||||
}
|
||||
|
||||
private Response getResponse(Request request) {
|
||||
return Response.builder()
|
||||
.setMimeType(MimeType.JSON)
|
||||
.setJSONContent(getStoredJSON(request).json)
|
||||
.build();
|
||||
}
|
||||
|
||||
private JSONStorage.StoredJSON getStoredJSON(Request request) {
|
||||
long timestamp = Identifiers.getTimestamp(request);
|
||||
JSONStorage.StoredJSON storedJSON;
|
||||
if (request.getQuery().get("server").isPresent()) {
|
||||
UUID serverUUID = identifiers.getServerUUID(request); // Can throw BadRequestException
|
||||
return JSONCache.getOrCache(DataID.PLAYERS, serverUUID, () -> jsonFactory.serverPlayersTableJSON(serverUUID));
|
||||
}
|
||||
storedJSON = jsonResolverService.resolve(timestamp, DataID.PLAYERS, serverUUID, jsonFactory::serverPlayersTableJSON);
|
||||
} else {
|
||||
// Assume players page
|
||||
return JSONCache.getOrCache(DataID.PLAYERS, jsonFactory::networkPlayersTableJSON);
|
||||
storedJSON = jsonResolverService.resolve(timestamp, DataID.PLAYERS, jsonFactory::networkPlayersTableJSON);
|
||||
}
|
||||
return storedJSON;
|
||||
}
|
||||
}
|
@ -87,7 +87,12 @@
|
||||
<!-- Page Heading -->
|
||||
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
||||
<h1 class="h3 mb-0 text-gray-800"><i class="sidebar-toggler fa fa-fw fa-bars"></i>${networkName}
|
||||
| Players</h1>
|
||||
| Players
|
||||
<span class="refresh-element">
|
||||
<i class="fa fa-fw fa-sync"></i> <span class="refresh-time"></span>
|
||||
<span class="refresh-notice"><i class="fa fa-fw fa-cog fa-spin"></i> Updating..</span>
|
||||
</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@ -265,10 +270,20 @@
|
||||
<script src="js/color-selector.js"></script>
|
||||
|
||||
<script id="mainScript">
|
||||
refreshBarrierMs = ${refreshBarrier};
|
||||
try {
|
||||
jsonRequest("./v1/players", function (playersTableJson, error) {
|
||||
let table;
|
||||
refreshingJsonRequest("./v1/players", function (playersTableJson, error) {
|
||||
if (playersTableJson) {
|
||||
$('.player-table').DataTable({
|
||||
if (table) {
|
||||
table.destroy();
|
||||
$('.player-table').replaceWith(`<table class="table table-bordered table-striped table-hover player-table dataTable">
|
||||
<tr>
|
||||
<td>Loading..</td>
|
||||
</tr>
|
||||
</table>`);
|
||||
}
|
||||
table = $('.player-table').DataTable({
|
||||
responsive: true,
|
||||
columns: playersTableJson.columns,
|
||||
data: playersTableJson.data,
|
||||
@ -277,7 +292,7 @@
|
||||
} else if (error) {
|
||||
$('.player-table').text("Failed to load Players table data: " + error);
|
||||
}
|
||||
});
|
||||
}, 'players', true);
|
||||
} catch (loadingError) {
|
||||
window.alert("Error occurred, see Developer Console (Ctrl+Shift+I) - Please report this: " + loadingError);
|
||||
setTimeout(function () {
|
||||
|
@ -875,7 +875,12 @@
|
||||
<!-- Page Heading -->
|
||||
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
||||
<h1 class="h3 mb-0 text-gray-800"><i class="sidebar-toggler fa fa-fw fa-bars"></i>${serverDisplayName}
|
||||
· Player List</h1>
|
||||
· Player List
|
||||
<span class="refresh-element">
|
||||
<i class="fa fa-fw fa-sync"></i> <span class="refresh-time"></span>
|
||||
<span class="refresh-notice"><i class="fa fa-fw fa-cog fa-spin"></i> Updating..</span>
|
||||
</span>
|
||||
</h1>
|
||||
${backButton}
|
||||
</div>
|
||||
|
||||
@ -1379,18 +1384,27 @@
|
||||
|
||||
setLoadingText('Sorting players table..');
|
||||
|
||||
jsonRequest("../v1/players?server=${serverUUID}", function (json, error) {
|
||||
let table;
|
||||
refreshingJsonRequest("../v1/players?server=${serverUUID}", function (json, error) {
|
||||
if (json) {
|
||||
$('.player-table').DataTable({
|
||||
if (table) {
|
||||
table.destroy();
|
||||
$('.player-table').replaceWith(`<table class="table table-bordered table-striped table-hover player-table dataTable">
|
||||
<tr>
|
||||
<td>Loading..</td>
|
||||
</tr>
|
||||
</table>`);
|
||||
}
|
||||
table = $('.player-table').DataTable({
|
||||
responsive: true,
|
||||
columns: json.columns,
|
||||
data: json.data,
|
||||
order: [[5, "desc"]]
|
||||
})
|
||||
});
|
||||
} else if (error) {
|
||||
$('.player-table').text("Failed to load Players table data: " + error);
|
||||
}
|
||||
});
|
||||
}, 'playerlist', true);
|
||||
refreshingJsonRequest("../v1/kills?server=${serverUUID}", loadPlayerKills, 'pvp-pve');
|
||||
refreshingJsonRequest("../v1/pingTable?server=${serverUUID}", loadPingTable, 'geolocations');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user