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

chore: refactor AliceChopperAdapter #191

Merged
merged 27 commits into from
Jun 9, 2024
Merged

chore: refactor AliceChopperAdapter #191

merged 27 commits into from
Jun 9, 2024

Conversation

techouse
Copy link
Collaborator

@techouse techouse commented Jun 8, 2024

This PR refactors the Alice Chopper interceptor even further by:

  • removing the deprecated alice_token turns out, alice_token is required to keep track of calls & responses
    • I opted into using UUIDv4 as the alice_token since it offers true uniqueness. In case this is not desired I can reverse back to microseconds. Note that milliseconds are NOT unique enough.
  • obtaining the body size in a safer way
  • getting rid of all unnecessary intermediary variables
  • updates the Alice Chopper example

@jhomlala
Copy link
Owner

jhomlala commented Jun 8, 2024

Hey, thanks for this refactor. When I run your adapter with alice_chopper example, it shows me this error. I think this is something with getRequestHashCode. Can you check it please?

I/flutter ( 9961): Bad state: No element
I/flutter ( 9961): #0      Iterable.reduce (dart:core/iterable.dart:375:7)
I/flutter ( 9961): #1      AliceChopperAdapter.getRequestHashCode (package:alice_chopper/alice_chopper_adapter.dart:21:14)
I/flutter ( 9961): #2      AliceChopperAdapter.intercept (package:alice_chopper/alice_chopper_adapter.dart:37:23)
I/flutter ( 9961): <asynchronous suspension>
I/flutter ( 9961): #3      InterceptorChain.proceed (package:chopper/src/chain/interceptor_chain.dart:46:16)
I/flutter ( 9961): <asynchronous suspension>
I/flutter ( 9961): #4      RequestConverterInterceptor.intercept (package:chopper/src/interceptors/request_converter_interceptor.dart:26:7)
I/flutter ( 9961): <asynchronous suspension>
I/flutter ( 9961): #5      InterceptorChain.proceed (package:chopper/src/chain/interceptor_chain.dart:46:16)
I/flutter ( 9961): <asynchronous suspension>
I/flutter ( 9961): #6      Call.execute (package:chopper/src/chain/call.dart:56:12)
I/flutter ( 9961): <asynchronous suspension>
I/flutter ( 9961): #7      ChopperClient.send (package:chopper/src/base.dart:175:22)
I/flutter ( 9961): <asynchronous suspension>

@techouse
Copy link
Collaborator Author

techouse commented Jun 8, 2024

Oops ... lemme check 🙈

@jhomlala
Copy link
Owner

jhomlala commented Jun 8, 2024

Maybe I was wrong and alice_token is required :)

@techouse
Copy link
Collaborator Author

techouse commented Jun 8, 2024

Fixed.

Since alice_token was previously always present map + reduce worked. After I removed it and the headers Map became empty this would throw an error, as is explained here.

To work around this I used fold with an initialValue of 0 instead.

@jhomlala
Copy link
Owner

jhomlala commented Jun 8, 2024

Amazing! It's not crashing anymore. But when I look into inspector, it looks like responses are not being added into call.

image
image

Could you please verify why it's happening? Also I see that Alice should have some unit tests. This is something for next PRs.

@techouse
Copy link
Collaborator Author

techouse commented Jun 8, 2024

I fixed it. Can you please check it again?

@jhomlala
Copy link
Owner

jhomlala commented Jun 8, 2024

image
Great! Some requests are still loading forever. Could you look again at it when you have some time? 👀

@techouse
Copy link
Collaborator Author

techouse commented Jun 8, 2024

Working on it. I pushed an update that fixed it, but has some analysis issues. I'll check again in the evening.

@jhomlala
Copy link
Owner

jhomlala commented Jun 8, 2024

No worries, take your time. Thanks!

@techouse
Copy link
Collaborator Author

techouse commented Jun 9, 2024

@jhomlala right, this should now work as expected.

It turns out that the alice_token is actually required to keep track of all the various AliceHttpCalls and AliceHttpResponses in the AliceCore, so I used UUIDv4 to generate it using https://pub.dev/packages/uuid. This does add another dependency and if this is not desired, then I can revert to using microseconds, i.e. DateTime.now(). microsecondsSinceEpoch.toString().

I've also done extensive work on the Alice + Chopper example.

CC / @Guldem

@jhomlala
Copy link
Owner

jhomlala commented Jun 9, 2024

@techouse Thanks for this amazing work! Yes, I think this UUID package is fine. Overall it's LGTM. Are you planning to add more refactors or are we ready to merge it?

@techouse
Copy link
Collaborator Author

techouse commented Jun 9, 2024

Are you planning to add more refactors or are we ready to merge it?

Nope. That's all she wrote. 🤣

@jhomlala jhomlala merged commit 0f3174b into jhomlala:master Jun 9, 2024
2 checks passed
@techouse techouse deleted the chore/remove-deprecated-alice-token-from-chopper-interceptor branch June 9, 2024 19:52
@jhomlala
Copy link
Owner

jhomlala commented Jun 9, 2024

Included in 1.0.3 version of alice_chopper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants