-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
feat: #132 - new method OpenFoodAPIClient.addProductFields #436
Conversation
New files: * `AddableProductFields.dart`: Fields of a `Product` that can be simply added. * `api_addProductFields_test.dart`: Unit/Integration tests around `OpenFoodAPIClient.addProductFields` Impacted file: * `openfoodfacts.dart`: new method `addProductFields`
Impacted files: * `AddableProductFields.dart`: added suggested exception. * `api_addProductFields_test.dart`: added Unit/Integration tests for stores and countries. * `openfoodfacts.dart`: replaced exception with suggested label.
@g123k ping |
} | ||
|
||
final Map<String, String> parameterMap = <String, String>{}; | ||
parameterMap.addAll(user.toData()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By curiosity, why don't you call Map.from(user.toData)
?
_checkStatus(status); | ||
|
||
// cumulative list | ||
String expectedValue = _getValue(field, product)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A StringBuffer
would be better, since you concatenate strings multiple times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@g123k StringBuffer
is never used in the whole project. Here we're talking about adding a String to a String twice, and checking the resulting value 3 times (that would mean 3 additional toString()
calls with StringBuffer
). In a test. That makes async calls to the back-end that take longer time than a String allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@g123k I had a hunch about StringBuffer
not being significantly faster than String
when you only concatenate two String
s and convert each time the result as a String
.
I've coded a test with the 2 solutions: with String
and with StringBuffer
.
test code
const String initialString = "init";
const List<String> additionalValues = <String>['djobi', 'djoba'];
final List<String> result = <String>[];
late int start;
late int end;
result.clear();
start = DateTime.now().microsecondsSinceEpoch;
final StringBuffer asStringBuffer = StringBuffer(initialString);
result.add(asStringBuffer.toString());
for (final String additionalValue in additionalValues) {
asStringBuffer.write(', $additionalValue');
result.add(asStringBuffer.toString());
}
end = DateTime.now().microsecondsSinceEpoch;
print('${end - start}: $result');
result.clear();
start = DateTime.now().microsecondsSinceEpoch;
String asString = initialString;
result.add(asString);
for (final String additionalValue in additionalValues) {
asString += ', $additionalValue';
result.add(asString);
}
end = DateTime.now().microsecondsSinceEpoch;
print('${end - start}: $result');
After several runs, I've noticed that the first block run is a bit slower than the other - regardless of StringBuffer
and String
. By approximately 1ms.
Can you afford that 1ms uncertainty for tests? I think so. If that's OK with you, please approve my PR. If you think there is a hidden performance potential, don't hesitate to keep this PR rejected and to run performance tests.
@g123k "Requested changes" don't look like an appropriate term to me in that case: "By curiosity", "would be better". We're talking about mere comments. |
True, but this one requires a change |
Ready to merge? |
I'm afraid not. |
New files:
AddableProductFields.dart
: Fields of aProduct
that can be simply added.api_addProductFields_test.dart
: Unit/Integration tests aroundOpenFoodAPIClient.addProductFields
Impacted file:
openfoodfacts.dart
: new methodaddProductFields
What
OpenFoodAPIClient.addProductFields
Part of