diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/node/svc/ControlNodeService.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/node/svc/ControlNodeService.java index 6883d70a..66a2b485 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/node/svc/ControlNodeService.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/node/svc/ControlNodeService.java @@ -360,22 +360,29 @@ public class ControlNodeService { } private List makeFileStorageBaseWithStorage(List storageIds) throws SQLException { - Map fileStorageBaseByBaseId = new HashMap<>(); - Map> fileStoragByBaseId = new HashMap<>(); + Map> fileStorageByBaseId = new HashMap<>(); for (var id : storageIds) { var storage = fileStorageService.getStorage(id); fileStorageBaseByBaseId.computeIfAbsent(storage.base().id(), k -> storage.base()); - fileStoragByBaseId.computeIfAbsent(storage.base().id(), k -> new ArrayList<>()).add(new FileStorageWithActions(storage)); + fileStorageByBaseId.computeIfAbsent(storage.base().id(), k -> new ArrayList<>()).add(new FileStorageWithActions(storage)); } List result = new ArrayList<>(); - for (var baseId : fileStorageBaseByBaseId.keySet()) { - result.add(new FileStorageBaseWithStorage(fileStorageBaseByBaseId.get(baseId), - fileStoragByBaseId.get(baseId) - )); + for (var baseId : fileStorageBaseByBaseId.keySet()) { + var base = fileStorageBaseByBaseId.get(baseId); + var items = fileStorageByBaseId.get(baseId); + + // Sort by timestamp, then by relPath + // this ensures that the newest file is listed last + items.sort(Comparator + .comparing(FileStorageWithActions::getTimestamp) + .thenComparing(FileStorageWithActions::getRelPath) + ); + + result.add(new FileStorageBaseWithStorage(base, items)); } return result;