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

Fix: Resolve ListParam equality issue for caching identical requests #2366

Merged
merged 6 commits into from
Jan 28, 2025

Conversation

suojae
Copy link
Contributor

@suojae suojae commented Jan 27, 2025

What this PR does

Resolves #2364

This PR addresses an issue with ListParam equality, where identical requests were not recognized as the same due to reference comparison of lists. This caused multiple identical requests to be sent to the server, even when caching was implemented.

Changes introduced

Updated ListParam's operator == to use DeepCollectionEquality for proper deep equality comparison of list contents.
Added relevant unit tests to validate the fix and ensure no regression.


New Pull Request Checklist

  • I have read the Documentation
  • I have searched for a similar pull request in the project and found none
  • I have updated this branch with the latest main branch to avoid conflicts (via merge from master or rebase)
  • I have added the required tests to prove the fix/feature I'm adding
  • I have updated the documentation (if necessary)
  • I have run the tests without failures
  • I have updated the CHANGELOG.md in the corresponding package

@suojae suojae requested a review from a team as a code owner January 27, 2025 02:26
@suojae suojae force-pushed the fix/listparam-deepequality branch 2 times, most recently from 074c483 to 3c9be01 Compare January 27, 2025 10:22
@suojae suojae force-pushed the fix/listparam-deepequality branch 2 times, most recently from ad4133d to 3e44fcb Compare January 27, 2025 10:29
@suojae
Copy link
Contributor Author

suojae commented Jan 27, 2025

Hi, I’ve updated the ListParam equality logic to use DeepCollectionEquality for proper caching of identical requests. The changes have passed the stable and beta workflows, but the min workflow is failing due to what seems to be a compatibility issue with dio_web_adapter and the fileAccessMode parameter in Dio.download.

Locally, tests which I wrote are passing, and I’ve verified the changes in compatible environments. Could you help me identify if the failure in the min workflow is due to an unsupported configuration or if additional changes are required?

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimum ability check fail is unrelated.

- Added test cases to validate unequal inputs (different values, different order).
- Confirmed current behavior considers order in equality checks.
Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thought about the test.

final param3 = const ListParam(['item3', 'item4'], ListFormat.csv);
final param4 = const ListParam(['item2', 'item1'], ListFormat.csv);

final cache = {param1: 'Cached Response'};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should directly compare their equality rather than using the map?

Copy link
Contributor Author

@suojae suojae Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

I feel keeping the Map test might be useful if someone intends to use ListParam as a key in a Map. However, I’d like to make sure I’m on the right track. Is your suggestion aimed at simplifying the tests, or do you think the Map test is unnecessary in this case? If direct comparison is preferred, I’m happy to follow that direction ☺️

Copy link
Contributor Author

@suojae suojae Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated the tests to use direct equality comparison instead of Map key checks. I think it aligns better with the readability and purpose of the tests.

Let me know if there’s anything else to refine!

commit log: 82e2f03

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is your suggestion aimed at simplifying the tests

Yes exactly. The PR is about the equality of the parameters so we should directly test their equality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I see your point now, focusing directly on equality makes the purpose of the tests much clearer of the PR. I appreciate the feedback :)

import 'package:test/test.dart';

void main() {
test('ListParam equality for Map key', () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making a ListParam test group here.

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@suojae suojae changed the title Fix: Resolve ListParam equality issue for caching identical requests #2365 Fix: Resolve ListParam equality issue for caching identical requests Jan 28, 2025
@AlexV525 AlexV525 merged commit b58b440 into cfug:main Jan 28, 2025
2 of 3 checks passed
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.

Dio caching issue with identical ListParam objects
2 participants