Stop JSON cache mismatch when UUID is missing

The check for {identifier}- meant that lookup for "PLAYERS_ONLINE-"
would also match "PLAYERS_ONLINE-{uuid}-" since start is the same

Fixed this by changing identifiers to PLAYERS_ONLINE_{uuid}-{timestamp}

Affects issues:
- Fixed #3404
This commit is contained in:
Aurora Lahtela 2024-01-21 19:21:41 +02:00
parent 1fdd3289a6
commit ae85f39871
2 changed files with 12 additions and 4 deletions

View File

@ -61,6 +61,6 @@ public enum DataID {
public String of(ServerUUID serverUUID) {
if (serverUUID == null) return name();
return name() + '-' + serverUUID;
return name() + "_" + serverUUID;
}
}

View File

@ -16,6 +16,7 @@
*/
package com.djrapitops.plan.delivery.webserver.cache;
import com.djrapitops.plan.identification.ServerUUID;
import com.djrapitops.plan.storage.file.PlanFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -145,7 +146,7 @@ class JSONStorageTest {
@Test
void storedWithLaterDateIsNotFetched() {
long timestamp = System.currentTimeMillis();
JSONStorage.StoredJSON stored = UNDER_TEST.storeJson("Identifier", Collections.singletonList("data"), timestamp);
UNDER_TEST.storeJson("Identifier", Collections.singletonList("data"), timestamp);
assertFalse(UNDER_TEST.fetchJsonMadeAfter("Identifier", timestamp + TimeUnit.DAYS.toMillis(1L)).isPresent());
}
@ -160,14 +161,21 @@ class JSONStorageTest {
@Test
void storedWithEarlierDateIsNotFetched() {
long timestamp = System.currentTimeMillis();
JSONStorage.StoredJSON stored = UNDER_TEST.storeJson("Identifier", Collections.singletonList("data"), timestamp);
UNDER_TEST.storeJson("Identifier", Collections.singletonList("data"), timestamp);
assertFalse(UNDER_TEST.fetchJsonMadeBefore("Identifier", timestamp - TimeUnit.DAYS.toMillis(1L)).isPresent());
}
@Test
void doesNotFetchWrongThing() {
long timestamp = System.currentTimeMillis();
JSONStorage.StoredJSON stored = UNDER_TEST.storeJson(DataID.SESSIONS_OVERVIEW.name(), Collections.singletonList("data"), timestamp);
UNDER_TEST.storeJson(DataID.SESSIONS_OVERVIEW.name(), Collections.singletonList("data"), timestamp);
assertFalse(UNDER_TEST.fetchJsonMadeBefore(DataID.SESSIONS.name(), timestamp + TimeUnit.DAYS.toMillis(1L)).isPresent());
}
@Test
void doesNotFetchWrongServer() {
long timestamp = System.currentTimeMillis();
UNDER_TEST.storeJson(DataID.SESSIONS_OVERVIEW.of(ServerUUID.randomUUID()), Collections.singletonList("data"), timestamp);
assertFalse(UNDER_TEST.fetchJsonMadeBefore(DataID.SESSIONS_OVERVIEW.name(), timestamp + TimeUnit.DAYS.toMillis(1L)).isPresent());
}
}