Skip to content

Commit 52e8075

Browse files
committed
fix: optimize gRPC command result serialization by refining scalar result handling and emission logic
1 parent a6578e6 commit 52e8075

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

grpcw/src/main/java/com/arcadedb/server/grpc/ArcadeDbGrpcService.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,37 +194,27 @@ public void executeCommand(ExecuteCommandRequest req, StreamObserver<ExecuteComm
194194
LogManager.instance().log(this, Level.FINE, "executeCommand(): returning rows ...");
195195

196196
int emitted = 0;
197-
198197
while (rs.hasNext()) {
199198

200199
Result result = rs.next();
200+
201201
if (result.isElement()) {
202-
affected++; // count modified/returned records
203-
if (emitted < maxRows) {
204-
// Convert Result to GrpcRecord, preserving aliases and all properties
205-
GrpcRecord grpcRecord = convertResultToGrpcRecord(result, db,
206-
new ProjectionConfig(true, ProjectionEncoding.PROJECTION_AS_JSON, 0));
207-
out.addRecords(grpcRecord);
208-
emitted++;
209-
}
202+
affected++;
210203
} else {
211-
212-
// Scalar / projection row (e.g., RETURN COUNT)
213-
214-
if (emitted < maxRows) {
215-
216-
GrpcRecord.Builder recB = GrpcRecord.newBuilder();
217-
218-
for (String p : result.getPropertyNames()) {
219-
220-
recB.putProperties(p, convertPropToGrpcValue(p, result));
204+
for (String p : result.getPropertyNames()) {
205+
Object v = result.getProperty(p);
206+
if (v instanceof Number n) {
207+
affected += n.longValue();
221208
}
222-
223-
out.addRecords(recB.build());
224-
225-
emitted++;
226209
}
210+
}
227211

212+
if (emitted < maxRows) {
213+
// Convert Result to GrpcRecord, preserving aliases and all properties
214+
GrpcRecord grpcRecord = convertResultToGrpcRecord(result, db,
215+
new ProjectionConfig(true, ProjectionEncoding.PROJECTION_AS_JSON, 0));
216+
out.addRecords(grpcRecord);
217+
emitted++;
228218
}
229219
}
230220
} else {

0 commit comments

Comments
 (0)