Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(dynamite): avoid duplicate uri parsing #1327

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/dynamite/dynamite/lib/src/builder/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ Iterable<Method> buildTags(
throw Exception('The resulting uri $path is not a valid uri template according to RFC 6570. $e');
}

code.writeln("final _uri = Uri.parse(UriTemplate('$path').expand(_parameters));");
code.writeln("final _path = UriTemplate('$path').expand(_parameters);");

if (dataType != null) {
returnDataType = dataType.name;
Expand All @@ -356,7 +356,7 @@ Iterable<Method> buildTags(
return DynamiteRawResponse<$returnDataType, $returnHeadersType>(
response: $client.executeRequest(
'$httpMethod',
_uri,
_path,
_headers,
_body,
''');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class Client extends DynamiteClient {
final headers = <String, String>{};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<void, GetHeaders>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
const {200},
Expand Down Expand Up @@ -109,11 +109,11 @@ class Client extends DynamiteClient {
final headers = <String, String>{};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/with_content/operation_id').expand(parameters));
final path = UriTemplate('/with_content/operation_id').expand(parameters);
return DynamiteRawResponse<void, WithContentOperationIdHeaders>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
const {200},
Expand Down Expand Up @@ -156,11 +156,11 @@ class Client extends DynamiteClient {
};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/with_content').expand(parameters));
final path = UriTemplate('/with_content').expand(parameters);
return DynamiteRawResponse<Uint8List, GetWithContentHeaders>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
const {200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,13 @@ class Client extends DynamiteClient {
dynamite_utils.checkPattern($enumPattern as String?, RegExp('[a-z]'), 'enumPattern');
parameters['enum_pattern'] = $enumPattern;

final uri = Uri.parse(
UriTemplate(
'/{?content_string*,content_parameter*,array*,bool*,string*,string_binary*,int*,double*,num*,object*,oneOf*,anyOf*,enum_pattern*}',
).expand(parameters),
);
final path = UriTemplate(
'/{?content_string*,content_parameter*,array*,bool*,string*,string_binary*,int*,double*,num*,object*,oneOf*,anyOf*,enum_pattern*}',
).expand(parameters);
return DynamiteRawResponse<JsonObject, void>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
const {200},
Expand Down Expand Up @@ -310,11 +308,11 @@ class Client extends DynamiteClient {
headers['num'] = $$num.toString();
}

final uri = Uri.parse(UriTemplate('/headers').expand(parameters));
final path = UriTemplate('/headers').expand(parameters);
return DynamiteRawResponse<JsonObject, void>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
const {200},
Expand Down Expand Up @@ -362,11 +360,11 @@ class Client extends DynamiteClient {
final $pathParameter = jsonSerializers.serialize(pathParameter, specifiedType: const FullType(String));
parameters['path_parameter'] = $pathParameter;

final uri = Uri.parse(UriTemplate('/{path_parameter}').expand(parameters));
final path = UriTemplate('/{path_parameter}').expand(parameters);
return DynamiteRawResponse<JsonObject, void>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
const {200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class Client extends DynamiteClient {
if (uint8List != null) {
body = uint8List;
}
final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<void, void>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
null,
Expand Down Expand Up @@ -119,11 +119,11 @@ class Client extends DynamiteClient {
if (string != null) {
body = utf8.encode(string);
}
final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<void, void>(
response: executeRequest(
'post',
uri,
path,
headers,
body,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class Client extends DynamiteClient {
};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<String, void>(
response: executeRequest(
'get',
uri,
path,
headers,
body,
null,
Expand Down Expand Up @@ -112,11 +112,11 @@ class Client extends DynamiteClient {
};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<String, void>(
response: executeRequest(
'put',
uri,
path,
headers,
body,
const {200},
Expand Down Expand Up @@ -163,11 +163,11 @@ class Client extends DynamiteClient {
};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<String, void>(
response: executeRequest(
'post',
uri,
path,
headers,
body,
null,
Expand Down Expand Up @@ -212,11 +212,11 @@ class Client extends DynamiteClient {
};
Uint8List? body;

final uri = Uri.parse(UriTemplate('/').expand(parameters));
final path = UriTemplate('/').expand(parameters);
return DynamiteRawResponse<String, void>(
response: executeRequest(
'patch',
uri,
path,
headers,
body,
const {200, 201},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ class Client extends DynamiteClient {
var $limit = jsonSerializers.serialize(limit, specifiedType: const FullType(int));
_parameters['limit'] = $limit;

final _uri = Uri.parse(UriTemplate('/pets{?tags*,limit*}').expand(_parameters));
final _path = UriTemplate('/pets{?tags*,limit*}').expand(_parameters);
return DynamiteRawResponse<BuiltList<Pet>, void>(
response: this.executeRequest(
'get',
_uri,
_path,
_headers,
_body,
const {200},
Expand Down Expand Up @@ -161,11 +161,11 @@ class Client extends DynamiteClient {

_headers['Content-Type'] = 'application/json';
_body = utf8.encode(json.encode(jsonSerializers.serialize(newPet, specifiedType: const FullType(NewPet))));
final _uri = Uri.parse(UriTemplate('/pets').expand(_parameters));
final _path = UriTemplate('/pets').expand(_parameters);
return DynamiteRawResponse<Pet, void>(
response: this.executeRequest(
'post',
_uri,
_path,
_headers,
_body,
const {200},
Expand Down Expand Up @@ -225,11 +225,11 @@ class Client extends DynamiteClient {
var $id = jsonSerializers.serialize(id, specifiedType: const FullType(int));
_parameters['id'] = $id;

final _uri = Uri.parse(UriTemplate('/pets/{id}').expand(_parameters));
final _path = UriTemplate('/pets/{id}').expand(_parameters);
return DynamiteRawResponse<Pet, void>(
response: this.executeRequest(
'get',
_uri,
_path,
_headers,
_body,
const {200},
Expand Down Expand Up @@ -287,11 +287,11 @@ class Client extends DynamiteClient {
var $id = jsonSerializers.serialize(id, specifiedType: const FullType(int));
_parameters['id'] = $id;

final _uri = Uri.parse(UriTemplate('/pets/{id}').expand(_parameters));
final _path = UriTemplate('/pets/{id}').expand(_parameters);
return DynamiteRawResponse<void, void>(
response: this.executeRequest(
'delete',
_uri,
_path,
_headers,
_body,
const {204},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class DynamiteClient {
/// All [baseHeaders] are added to the request.
Future<HttpClientResponse> executeRequest(
final String method,
final Uri path,
final String path,
final Map<String, String> headers,
final Uint8List? body,
final Set<int>? validStatuses,
Expand Down
Loading