Copilot commented on code in PR #2859:
URL:
https://github.com/apache/incubator-hugegraph/pull/2859#discussion_r2313298884
##########
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 {
+ assert vertex != null;
Review Comment:
This assertion is redundant since the condition `vertex.expired()` being
false already guarantees that `vertex` is not null at this point.
```suggestion
```
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -934,57 +1012,121 @@ public Edge queryEdge(Object edgeId) {
return edge;
}
+ @Watched(prefix = "graph")
protected Iterator<Edge> queryEdgesByIds(Object[] edgeIds,
boolean verifyId) {
Query.checkForceCapacity(edgeIds.length);
- // NOTE: allowed duplicated edges if query by duplicated ids
- List<Id> ids = InsertionOrderUtil.newList();
- Map<Id, HugeEdge> edges = new HashMap<>(edgeIds.length);
+ List<Id> ids;
+ Map<Id, HugeEdge> edges;
+ boolean edgesUpdated = this.edgesInTxSize() > 0;
- IdQuery query = new IdQuery(HugeType.EDGE);
- for (Object edgeId : edgeIds) {
- HugeEdge edge;
- EdgeId id = HugeEdge.getIdValue(edgeId, !verifyId);
+ if (edgeIds.length == 1) {
+ EdgeId id = HugeEdge.getIdValue(edgeIds[0], !verifyId);
+
+ boolean tryQueryBackend = true;
if (id == null) {
- continue;
+ tryQueryBackend = false;
+ ids = ImmutableList.of();
+ } else {
+ if (id.direction() == Directions.IN) {
+ id = id.switchDirection();
+ }
+ ids = ImmutableList.of(id);
+ }
+
+ HugeEdge edge = null;
+ if (id != null && edgesUpdated) {
+ if (this.removedEdges.containsKey(id)) {
+ // The record has been deleted
+ tryQueryBackend = false;
+ } else if ((edge = this.addedEdges.get(id)) != null ||
+ (edge = this.updatedEdges.get(id)) != null) {
+ // Found from local tx
+ tryQueryBackend = false;
+ if (edge.expired()) {
+ edge = null;
+ } else {
+ assert edge != null;
Review Comment:
This assertion is redundant since the condition `edge.expired()` being false
already guarantees that `edge` is not null at this point.
```suggestion
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]