imbajin commented on code in PR #2859:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2859#discussion_r2313277326


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -775,40 +784,103 @@ protected Iterator<Vertex> queryVerticesByIds(Object[] 
vertexIds, boolean adjace
         return this.queryVerticesByIds(vertexIds, adjacentVertex, 
checkMustExist, HugeType.VERTEX);
     }
 
+    @Watched(prefix = "graph")
     protected Iterator<Vertex> queryVerticesByIds(Object[] vertexIds, boolean 
adjacentVertex,
                                                   boolean checkMustExist, 
HugeType type) {
         Query.checkForceCapacity(vertexIds.length);
 
-        // NOTE: allowed duplicated vertices if query by duplicated ids
-        List<Id> ids = InsertionOrderUtil.newList();
-        Map<Id, HugeVertex> vertices = new HashMap<>(vertexIds.length);
+        List<Id> ids;
+        Map<Id, HugeVertex> vertices;
+        boolean verticesUpdated = this.verticesInTxSize() > 0;
 
-        IdQuery query = new IdQuery(type);
-        for (Object vertexId : vertexIds) {
-            HugeVertex vertex;
-            Id id = HugeVertex.getIdValue(vertexId);
-            if (id == null || this.removedVertices.containsKey(id)) {
-                // The record has been deleted
-                continue;
-            } else if ((vertex = this.addedVertices.get(id)) != null ||
-                       (vertex = this.updatedVertices.get(id)) != null) {
-                if (vertex.expired()) {
-                    continue;
+        if (vertexIds.length == 1) {
+            Id id = HugeVertex.getIdValue(vertexIds[0]);
+
+            boolean tryQueryBackend = true;
+            if (id == null) {
+                tryQueryBackend = false;
+                ids = ImmutableList.of();
+            } else {
+                ids = ImmutableList.of(id);
+            }
+
+            HugeVertex vertex = null;
+            if (id != null && verticesUpdated) {
+                if (this.removedVertices.containsKey(id)) {
+                    // The record has been deleted
+                    tryQueryBackend = false;
+                } else if ((vertex = this.addedVertices.get(id)) != null ||
+                           (vertex = this.updatedVertices.get(id)) != null) {
+                    // Found from local tx
+                    tryQueryBackend = false;
+                    if (vertex.expired()) {
+                        vertex = null;
+                    } else {

Review Comment:
   Consider extracting the local transaction lookup logic to reduce code 
duplication between single-ID and multi-ID paths. This pattern repeats in both 
vertex and edge queries:
   
   ```java
   private HugeVertex findVertexInLocalTx(Id id) {
       if (this.removedVertices.containsKey(id)) {
           return null; // Removed
       }
       HugeVertex vertex = this.addedVertices.get(id);
       if (vertex == null) {
           vertex = this.updatedVertices.get(id);
       }
       return (vertex != null && !vertex.expired()) ? vertex : null;
   }
   ```
   
   This would simplify the control flow and make the code more maintainable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org
For additional commands, e-mail: issues-h...@hugegraph.apache.org

Reply via email to