mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +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.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||||
import com.djrapitops.plan.settings.config.paths.ProxySettings;
|
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.locale.Locale;
|
||||||
import com.djrapitops.plan.settings.theme.Theme;
|
import com.djrapitops.plan.settings.theme.Theme;
|
||||||
import com.djrapitops.plan.version.VersionChecker;
|
import com.djrapitops.plan.version.VersionChecker;
|
||||||
@ -60,6 +61,7 @@ public class PlayersPage implements Page {
|
|||||||
public String toHtml() {
|
public String toHtml() {
|
||||||
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||||
|
|
||||||
|
placeholders.put("refreshBarrier", config.get(WebserverSettings.REDUCED_REFRESH_BARRIER));
|
||||||
placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
|
placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
|
||||||
placeholders.put("updateModal", versionChecker.getUpdateModal());
|
placeholders.put("updateModal", versionChecker.getUpdateModal());
|
||||||
placeholders.put("contributors", Contributors.generateContributorHtml());
|
placeholders.put("contributors", Contributors.generateContributorHtml());
|
||||||
|
@ -17,12 +17,14 @@
|
|||||||
package com.djrapitops.plan.delivery.webserver.resolver.json;
|
package com.djrapitops.plan.delivery.webserver.resolver.json;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.rendering.json.JSONFactory;
|
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.Resolver;
|
||||||
import com.djrapitops.plan.delivery.web.resolver.Response;
|
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.Request;
|
||||||
import com.djrapitops.plan.delivery.web.resolver.request.WebUser;
|
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.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONStorage;
|
||||||
import com.djrapitops.plan.identification.Identifiers;
|
import com.djrapitops.plan.identification.Identifiers;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -39,14 +41,17 @@ import java.util.UUID;
|
|||||||
public class PlayersTableJSONResolver implements Resolver {
|
public class PlayersTableJSONResolver implements Resolver {
|
||||||
|
|
||||||
private final Identifiers identifiers;
|
private final Identifiers identifiers;
|
||||||
|
private final AsyncJSONResolverService jsonResolverService;
|
||||||
private final JSONFactory jsonFactory;
|
private final JSONFactory jsonFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PlayersTableJSONResolver(
|
public PlayersTableJSONResolver(
|
||||||
Identifiers identifiers,
|
Identifiers identifiers,
|
||||||
|
AsyncJSONResolverService jsonResolverService,
|
||||||
JSONFactory jsonFactory
|
JSONFactory jsonFactory
|
||||||
) {
|
) {
|
||||||
this.identifiers = identifiers;
|
this.identifiers = identifiers;
|
||||||
|
this.jsonResolverService = jsonResolverService;
|
||||||
this.jsonFactory = jsonFactory;
|
this.jsonFactory = jsonFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +71,22 @@ public class PlayersTableJSONResolver implements Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response getResponse(Request request) {
|
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()) {
|
if (request.getQuery().get("server").isPresent()) {
|
||||||
UUID serverUUID = identifiers.getServerUUID(request); // Can throw BadRequestException
|
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
|
// 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 -->
|
<!-- Page Heading -->
|
||||||
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
<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}
|
<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>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -265,10 +270,20 @@
|
|||||||
<script src="js/color-selector.js"></script>
|
<script src="js/color-selector.js"></script>
|
||||||
|
|
||||||
<script id="mainScript">
|
<script id="mainScript">
|
||||||
|
refreshBarrierMs = ${refreshBarrier};
|
||||||
try {
|
try {
|
||||||
jsonRequest("./v1/players", function (playersTableJson, error) {
|
let table;
|
||||||
|
refreshingJsonRequest("./v1/players", function (playersTableJson, error) {
|
||||||
if (playersTableJson) {
|
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,
|
responsive: true,
|
||||||
columns: playersTableJson.columns,
|
columns: playersTableJson.columns,
|
||||||
data: playersTableJson.data,
|
data: playersTableJson.data,
|
||||||
@ -277,7 +292,7 @@
|
|||||||
} else if (error) {
|
} else if (error) {
|
||||||
$('.player-table').text("Failed to load Players table data: " + error);
|
$('.player-table').text("Failed to load Players table data: " + error);
|
||||||
}
|
}
|
||||||
});
|
}, 'players', true);
|
||||||
} catch (loadingError) {
|
} catch (loadingError) {
|
||||||
window.alert("Error occurred, see Developer Console (Ctrl+Shift+I) - Please report this: " + loadingError);
|
window.alert("Error occurred, see Developer Console (Ctrl+Shift+I) - Please report this: " + loadingError);
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -875,7 +875,12 @@
|
|||||||
<!-- Page Heading -->
|
<!-- Page Heading -->
|
||||||
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
<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}
|
<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}
|
${backButton}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1379,18 +1384,27 @@
|
|||||||
|
|
||||||
setLoadingText('Sorting players table..');
|
setLoadingText('Sorting players table..');
|
||||||
|
|
||||||
jsonRequest("../v1/players?server=${serverUUID}", function (json, error) {
|
let table;
|
||||||
|
refreshingJsonRequest("../v1/players?server=${serverUUID}", function (json, error) {
|
||||||
if (json) {
|
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,
|
responsive: true,
|
||||||
columns: json.columns,
|
columns: json.columns,
|
||||||
data: json.data,
|
data: json.data,
|
||||||
order: [[5, "desc"]]
|
order: [[5, "desc"]]
|
||||||
})
|
});
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
$('.player-table').text("Failed to load Players table data: " + error);
|
$('.player-table').text("Failed to load Players table data: " + error);
|
||||||
}
|
}
|
||||||
});
|
}, 'playerlist', true);
|
||||||
refreshingJsonRequest("../v1/kills?server=${serverUUID}", loadPlayerKills, 'pvp-pve');
|
refreshingJsonRequest("../v1/kills?server=${serverUUID}", loadPlayerKills, 'pvp-pve');
|
||||||
refreshingJsonRequest("../v1/pingTable?server=${serverUUID}", loadPingTable, 'geolocations');
|
refreshingJsonRequest("../v1/pingTable?server=${serverUUID}", loadPingTable, 'geolocations');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user