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

Migrate search to SDK to fix cancellation issues #2727

Merged
merged 3 commits into from
May 17, 2023

Conversation

polson
Copy link
Contributor

@polson polson commented Apr 30, 2023

Changes
* Extends ItemItemRowAdapter and provides a suspending function for the search logic
* Suspending function is canceled when a new search happens
See comment below

The issue was caused by the old API client using Volley for HTTP requests, which launches a thread. It does not use a coroutine / suspending function, so even though the coroutine is being canceled with new search input, the api call is not.

Issues
#2726

@polson polson force-pushed the fix-search-cancellation branch from 5cda6e9 to df00ce1 Compare April 30, 2023 21:10
@polson
Copy link
Contributor Author

polson commented May 1, 2023

I think I would like to change this by doing a small refactor:

  • Share a viewmodel between the two search fragments.
  • Make the search call in the viewmodel.
  • Pass the SearchHints to the ItemRowAdapter directly

Then we can move the search networking out of the ItemRowAdapter entirely. I noticed we're already doing this in a few places. There's an ItemRowAdapter constructor that takes in a list of ChapterItemInfo for example.

One annoying thing about this however is if we try to pass in a list of SearchHint it will conflict with that constructor because of type erasure. I dealt with this by passing in a Collection instead of a List

@polson polson force-pushed the fix-search-cancellation branch 3 times, most recently from b9235a0 to 2eec7c6 Compare May 1, 2023 05:16
@polson polson force-pushed the fix-search-cancellation branch 5 times, most recently from bc12135 to 4b9dd31 Compare May 1, 2023 17:58
@polson polson force-pushed the fix-search-cancellation branch 3 times, most recently from 3135fe8 to b33cd13 Compare May 2, 2023 05:11
@nielsvanvelzen
Copy link
Member

If we're migrating the search code to the SDK we should use the items API with the searchTerm parameter for the query instead. This API returns normal BaseItemDto models instead of search hints. The web client also uses this approach for searching.

@polson polson force-pushed the fix-search-cancellation branch 5 times, most recently from a5181fa to 5a64896 Compare May 9, 2023 23:21
@polson
Copy link
Contributor Author

polson commented May 9, 2023

Updated this to use the new search api

@polson polson force-pushed the fix-search-cancellation branch 3 times, most recently from 38c9426 to 9f67e3c Compare May 11, 2023 17:10
@nielsvanvelzen nielsvanvelzen added this to the v0.16.0 milestone May 13, 2023
@nielsvanvelzen nielsvanvelzen added bug Something isn't working enhancement New feature or request sdk-migration To fix this we need to migrate some code to the new SDK labels May 13, 2023
@jellyfin-bot jellyfin-bot added the merge conflict Conflicts prevent merging label May 13, 2023
@polson polson force-pushed the fix-search-cancellation branch from 9f67e3c to 54f6f53 Compare May 13, 2023 17:11
@jellyfin-bot jellyfin-bot removed the merge conflict Conflicts prevent merging label May 13, 2023
@polson polson marked this pull request as draft May 13, 2023 17:15
@polson polson force-pushed the fix-search-cancellation branch from 54f6f53 to d8aa16a Compare May 13, 2023 17:18
@polson polson marked this pull request as ready for review May 13, 2023 17:19
@polson
Copy link
Contributor Author

polson commented May 13, 2023

Addressed comments

@polson polson force-pushed the fix-search-cancellation branch from d8aa16a to e4c7262 Compare May 13, 2023 17:23
@polson polson requested a review from nielsvanvelzen May 13, 2023 17:28
@polson polson force-pushed the fix-search-cancellation branch from e4c7262 to 11f32cb Compare May 13, 2023 17:43
Copy link
Member

@nielsvanvelzen nielsvanvelzen left a comment

Choose a reason for hiding this comment

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

Some files are indented with spaces instead of tabs, and a lot of places use (like constructors) use 2x the amount of indent compared to existing code.

@polson
Copy link
Contributor Author

polson commented May 13, 2023

Sorry about the whitespace changes, I tend to use the AS formatter quite frequently so that's why it moved things around

@nielsvanvelzen
Copy link
Member

Hmm that's weird, the default Android Studio config + our editorconfig should configure the formatter properly. I use it all the time. Maybe it broke in a newer version? I'll look into it.

@polson
Copy link
Contributor Author

polson commented May 15, 2023

I tried out the Canary build of AS and I think that messed up the autoformatter. I'll fix it in the PR

@polson polson force-pushed the fix-search-cancellation branch 2 times, most recently from 17b5721 to 8a56e2b Compare May 15, 2023 23:25
@polson polson force-pushed the fix-search-cancellation branch from 8a56e2b to d73857b Compare May 15, 2023 23:25
@polson polson requested a review from nielsvanvelzen May 15, 2023 23:27
Copy link
Member

@nielsvanvelzen nielsvanvelzen left a comment

Choose a reason for hiding this comment

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

I've made some additional changes;

  • Updates formatting
  • Moved searchJob?.cancel() to before the query.isBlank check to prevent a race condition where items wouldn't be cleared when emptying the input.

Thanks a lot for the pull request!

@nielsvanvelzen nielsvanvelzen changed the title Cancel search requests when search box input changes Migrate search to SDK to fix cancellation issues May 17, 2023
@nielsvanvelzen nielsvanvelzen enabled auto-merge (rebase) May 17, 2023 10:40
@nielsvanvelzen nielsvanvelzen merged commit 369c5bf into jellyfin:master May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request sdk-migration To fix this we need to migrate some code to the new SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants