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

Feature/add to up next after sync #3212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stic
Copy link

@stic stic commented Nov 11, 2024

Description

Attempt to defer addition to UpNext these episodes that are new (post update) but might have been already finished, archived or added to UpNext on another device. The update of UpNext got extracted as a separate function, filter was added (potentially causing some slowdown as it would check if episodes aren't finished, archived or already on the UpNext list).
Must admit I'm not 100% sure that UpNext sync will always finish by the time we return from sync(), so if anything logic there might be slightly broken (still don't got into duplicated or missing items on UpNext after some testing)

Fixes #3211

Testing Instructions

  1. To test, you would need two devices, one setup to add episodes to UpNext (another that doesn't)
  2. Make sure you have background refresh / update turned off.
  3. On the device that doesn't sync, pick an episode that should be added to UpNext (sometimes it takes a while for that to happen) on the device adding to UpNext
  4. Listen to that episode(s)
  5. Open and observe UpNext syncing on 1st device - before fix it would put the episode on UpNext, download and in a while remove
  6. Postfix episode doesn't show up on UpNext, doesn't download, is seen as archived / played

Screenshots or Screencast

Need to get my head around how to create these.

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

I have tested any UI changes...

N/A

@stic stic requested a review from a team as a code owner November 11, 2024 22:10
@stic stic requested review from ashiagr and removed request for a team November 11, 2024 22:10
@CLAassistant
Copy link

CLAassistant commented Nov 11, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@ashiagr ashiagr left a comment

Choose a reason for hiding this comment

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

I left two minor comments.
It works! 🙂 We'll further monitor it in 7.78 beta.

@@ -291,16 +293,15 @@ class RefreshPodcastsThread(
settings.setRefreshState(settings.getLastSuccessRefreshState() ?: RefreshState.Never)
}

private fun updatePodcasts(result: RefreshResponse?): List<String> {
private data class AddedEpisodes(val episodeUuidsAdded: List<String>, val episodesToAddToUpNext: MutableList<Pair<AddToUpNext, PodcastEpisode>>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we convert episodesToAddToUpNext to immutable List and make it mutable when needed?

Comment on lines +370 to +372
episodesToAddToUpNext.removeAll { runBlocking { true == episodeManager.findByUuid(it.second.uuid)?.isFinished ||
true == episodeManager.findByUuid(it.second.uuid)?.isArchived ||
playbackManager.upNextQueue.contains(it.second.uuid)} }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we find matching episodes using a single query using findEpisodesByUuids? Something like below to avoid multiple DB interactions?

val episodeToBeRemovedUuids = episodeManager.findEpisodesByUuids(episodesToAddToUpNext.map { it.second.uuid })
                .filter { it.isFinished || it.isArchived || playbackManager.upNextQueue.contains(it.uuid) }
                .map { it.uuid }

and then remove those uuids here?

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.

Add new episodes to UpNext and trigger download after (not before) sync
3 participants