-
Notifications
You must be signed in to change notification settings - Fork 135
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
End of Year: improve listening history sync #523
End of Year: improve listening history sync #523
Conversation
@@ -205,7 +205,7 @@ class EndOfYearDataManager { | |||
WHERE `\(DataManager.podcastTableName)`.uuid = `\(DataManager.episodeTableName)`.podcastUuid and | |||
\(listenedEpisodesThisYear) | |||
GROUP BY podcastUuid | |||
ORDER BY played_episodes DESC | |||
ORDER BY totalPlayedTime DESC |
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.
I changed that because if a person listened to, let's say, 40 episodes of a podcast that has 1-minute episodes, that would be their top podcast. Which is weird (and we already received feedback about that).
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.
Left a few comments.
@@ -933,4 +933,8 @@ public extension DataManager { | |||
func longestEpisode() -> Episode? { | |||
endOfYearManager.longestEpisode(dbQueue: dbQueue) | |||
} | |||
|
|||
func episodesThatExists(uuids: [String]) -> [String] { |
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.
func episodesThatExists(uuids: [String]) -> [String] { | |
func episodesThatExist(uuids: [String]) -> [String] { |
@@ -256,6 +256,32 @@ class EndOfYearDataManager { | |||
return episode | |||
} | |||
|
|||
/// Given a list of UUIDs, return which UUIDs are present on the database | |||
func episodesThatExists(dbQueue: FMDatabaseQueue, uuids: [String]) -> [String] { |
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.
func episodesThatExists(dbQueue: FMDatabaseQueue, uuids: [String]) -> [String] { | |
func episodesThatExist(dbQueue: FMDatabaseQueue, uuids: [String]) -> [String] { |
Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/EndOfYearDataManager.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Emily Laguna <[email protected]>
This PR improves and speeds up the process of syncing the 2022 listening history. I tested with an account that was taking ~6 minutes to sync. This has been reduced to ~34s. There's still room for improvement but I'll leave that for another PR.
Before the change: sync took 296.6710090637207
After the change: sync took 34.58926796913147
Improvements
The way we were doing before, we would check the database once per episode, it doesn't matter if the user had them or not. For users with a big list of episodes, the performance was very poor.
Instead, what we do now is to check the episodes that are missing and request and add only them.
To test
Checklist
CHANGELOG.md
if necessary.