mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 19:51:25 +01:00
Fixed JSONStorage sometimes fetching the wrong thing
This commit is contained in:
parent
19b64455b4
commit
ac9ca5949e
@ -124,7 +124,7 @@ public class JSONFileStorage implements JSONStorage {
|
|||||||
if (stored == null) return Optional.empty();
|
if (stored == null) return Optional.empty();
|
||||||
for (File file : stored) {
|
for (File file : stored) {
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier)) {
|
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier + '-')) {
|
||||||
return Optional.ofNullable(readStoredJSON(file));
|
return Optional.ofNullable(readStoredJSON(file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ public class JSONFileStorage implements JSONStorage {
|
|||||||
for (File file : stored) {
|
for (File file : stored) {
|
||||||
try {
|
try {
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier)) {
|
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier + '-')) {
|
||||||
Matcher timestampMatch = timestampRegex.matcher(fileName);
|
Matcher timestampMatch = timestampRegex.matcher(fileName);
|
||||||
if (timestampMatch.find() && timestampComparator.test(timestampMatch, timestamp)) {
|
if (timestampMatch.find() && timestampComparator.test(timestampMatch, timestamp)) {
|
||||||
return Optional.ofNullable(readStoredJSON(file));
|
return Optional.ofNullable(readStoredJSON(file));
|
||||||
@ -203,7 +203,7 @@ public class JSONFileStorage implements JSONStorage {
|
|||||||
private boolean shouldDeleteFile(String identifier, long timestamp, File file) {
|
private boolean shouldDeleteFile(String identifier, long timestamp, File file) {
|
||||||
try {
|
try {
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier)) {
|
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier + '-')) {
|
||||||
Matcher timestampMatch = timestampRegex.matcher(fileName);
|
Matcher timestampMatch = timestampRegex.matcher(fileName);
|
||||||
if (timestampMatch.find() && Long.parseLong(timestampMatch.group(1)) < timestamp) {
|
if (timestampMatch.find() && Long.parseLong(timestampMatch.group(1)) < timestamp) {
|
||||||
return true;
|
return true;
|
||||||
@ -237,7 +237,7 @@ public class JSONFileStorage implements JSONStorage {
|
|||||||
boolean isOlder = timestampMatch.find() && Long.parseLong(timestampMatch.group(1)) < timestamp;
|
boolean isOlder = timestampMatch.find() && Long.parseLong(timestampMatch.group(1)) < timestamp;
|
||||||
if (isOlder) {
|
if (isOlder) {
|
||||||
for (String ignoredIdentifier : ignoredIdentifiers) {
|
for (String ignoredIdentifier : ignoredIdentifiers) {
|
||||||
if (fileName.startsWith(ignoredIdentifier)) return false;
|
if (fileName.startsWith(ignoredIdentifier + "-")) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -163,4 +163,11 @@ class JSONStorageTest {
|
|||||||
JSONStorage.StoredJSON stored = UNDER_TEST.storeJson("Identifier", Collections.singletonList("data"), timestamp);
|
JSONStorage.StoredJSON stored = UNDER_TEST.storeJson("Identifier", Collections.singletonList("data"), timestamp);
|
||||||
assertFalse(UNDER_TEST.fetchJsonMadeBefore("Identifier", timestamp - TimeUnit.DAYS.toMillis(1L)).isPresent());
|
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);
|
||||||
|
assertFalse(UNDER_TEST.fetchJsonMadeBefore(DataID.SESSIONS.name(), timestamp + TimeUnit.DAYS.toMillis(1L)).isPresent());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user