Skip to content

Commit

Permalink
Merge pull request #81 from ballerina-platform/callMethodImprovement
Browse files Browse the repository at this point in the history
Remove unnecessary metadata objects for same strand calls
  • Loading branch information
warunalakshitha authored Nov 28, 2024
2 parents 32b7869 + 4e4963c commit 9329846
Showing 1 changed file with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package io.ballerina.stdlib.persist.googlesheets.datastore;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.concurrent.StrandMetadata;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.RecordType;
import io.ballerina.runtime.api.values.BArray;
Expand All @@ -31,8 +30,6 @@
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.stdlib.persist.googlesheets.Utils;

import java.util.Map;

import static io.ballerina.stdlib.persist.Constants.KEY_FIELDS;
import static io.ballerina.stdlib.persist.Constants.RUN_READ_QUERY_METHOD;
import static io.ballerina.stdlib.persist.ErrorGenerator.wrapError;
Expand All @@ -41,7 +38,6 @@
import static io.ballerina.stdlib.persist.Utils.getMetadata;
import static io.ballerina.stdlib.persist.Utils.getPersistClient;
import static io.ballerina.stdlib.persist.Utils.getRecordTypeWithKeyFields;
import static io.ballerina.stdlib.persist.Utils.getTransactionContextProperties;
import static io.ballerina.stdlib.persist.googlesheets.Constants.RUN_READ_TABLE_AS_STREAM_METHOD;
import static io.ballerina.stdlib.persist.googlesheets.Utils.getEntityFromStreamMethod;
import static io.ballerina.stdlib.persist.googlesheets.Utils.getFieldTypes;
Expand Down Expand Up @@ -74,8 +70,6 @@ public static BStream query(Environment env, BObject client, BTypedesc targetTyp
BArray includes = metadata[1];
BArray typeDescriptions = metadata[2];
BMap<BString, Object> typeMap = getFieldTypes(recordType);

Map<String, Object> trxContextProperties = getTransactionContextProperties();
return env.yieldAndRun(() -> {
try {
Object result = env.getRuntime().callMethod(
Expand All @@ -84,8 +78,7 @@ public static BStream query(Environment env, BObject client, BTypedesc targetTyp
// string[] include = []
// )`
// which returns `stream<record{}|error?>|persist:Error`
persistClient, RUN_READ_QUERY_METHOD, new StrandMetadata(false, trxContextProperties),
targetTypeWithIdFields, typeMap, fields, includes);
persistClient, RUN_READ_QUERY_METHOD, null, targetTypeWithIdFields, typeMap, fields, includes);
if (result instanceof BStream bStream) { // stream<record {}, redis:Error?>
return Utils.createPersistGSheetsStreamValue(bStream, targetType, fields, includes,
typeDescriptions, persistClient, null);
Expand Down Expand Up @@ -116,8 +109,6 @@ public static BStream queryStream(Environment env, BObject client, BTypedesc tar
BArray includes = metadata[1];
BArray typeDescriptions = metadata[2];
BMap<BString, Object> typeMap = getFieldTypes(recordType);

Map<String, Object> trxContextProperties = getTransactionContextProperties();
return env.yieldAndRun(() -> {
try {
Object result = env.getRuntime().callMethod(
Expand All @@ -126,8 +117,8 @@ public static BStream queryStream(Environment env, BObject client, BTypedesc tar
// string[] include = []
// )`
// which returns `stream<record{}|error?>|persist:Error`
persistClient, RUN_READ_TABLE_AS_STREAM_METHOD, new StrandMetadata(false, trxContextProperties),
targetTypeWithIdFields, typeMap, fields, includes);
persistClient, RUN_READ_TABLE_AS_STREAM_METHOD, null, targetTypeWithIdFields, typeMap, fields
, includes);
if (result instanceof BStream bStream) { // stream<record {}, redis:Error?>
return Utils.createPersistGSheetsStreamValue(bStream, targetType, fields, includes,
typeDescriptions, persistClient, null);
Expand Down Expand Up @@ -159,8 +150,6 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp
BArray typeDescriptions = metadata[2];
BMap<BString, Object> typeMap = getFieldTypes(recordType);
Object key = getKey(env, path);

Map<String, Object> trxContextProperties = getTransactionContextProperties();
return env.yieldAndRun(() -> {
try {
return env.getRuntime().callMethod(
Expand All @@ -169,8 +158,8 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp
// string[] include = []
// )`
// which returns `stream<record{}|error?>|persist:Error`
persistClient, RUN_READ_TABLE_AS_STREAM_METHOD, new StrandMetadata(false, trxContextProperties),
targetType, targetTypeWithIdFields, typeMap, key, fields, includes, typeDescriptions);
persistClient, RUN_READ_TABLE_AS_STREAM_METHOD, null, targetType, targetTypeWithIdFields,
typeMap, key, fields, includes, typeDescriptions);
} catch (BError bError) {
return wrapError(bError);
}
Expand Down

0 comments on commit 9329846

Please sign in to comment.