From b6be12db92643d1053488fbf711221078368a768 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 17 Jan 2023 20:49:46 +0100 Subject: [PATCH] Fix: Optimize generateBreadcrumbs --- src/de/steamwar/sql/SchematicNode.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/sql/SchematicNode.java b/src/de/steamwar/sql/SchematicNode.java index df7d4b4..06f1eb0 100644 --- a/src/de/steamwar/sql/SchematicNode.java +++ b/src/de/steamwar/sql/SchematicNode.java @@ -501,12 +501,20 @@ public class SchematicNode { public String generateBreadcrumbs(String split) { StringBuilder builder = new StringBuilder(getName()); Optional currentNode = Optional.of(this); - List parents = SchematicNode.parentsOfNode(SteamwarUser.get(effectiveOwner), nodeId); if(currentNode.map(SchematicNode::isDir).orElse(false)) { builder.append(split); } while (currentNode.isPresent()) { - currentNode = currentNode.flatMap(SchematicNode::getOptionalParent).flatMap(integer -> parents.stream().filter(schematicNode -> schematicNode.getId() == integer).findFirst()); + currentNode = currentNode.flatMap(SchematicNode::getOptionalParent).map(integer -> { + NodeMember member = NodeMember.getNodeMember(integer, nodeOwner); + if (member != null) { + integer = member.getParent().orElse(null); + if(integer == null) { + return null; + } + } + return SchematicNode.getSchematicNode(integer); + }); currentNode.ifPresent(node -> builder.insert(0, split).insert(0, node.getName())); } return builder.toString(); @@ -552,7 +560,8 @@ public class SchematicNode { SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab); if (pa == null) return Collections.emptyList(); List nodes = SchematicNode.list(user, pa.getId()); - nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs())); + String br = pa.generateBreadcrumbs(); + nodes.forEach(node -> list.add((sws ? "/" : "") + br + node.getName())); } else { List nodes = SchematicNode.list(user, null); nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : ""))); -- 2.39.5