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

iTunes: Share common import logic between XML and macOS #11500

Merged
merged 21 commits into from
Apr 25, 2023

Conversation

fwcd
Copy link
Member

@fwcd fwcd commented Apr 19, 2023

This factors out the common, non-format-dependent logic between the iTunes importers into a new class ITunesDAO (feel free to suggest a better name), namely

  • Database queries
  • Duplicate resolution
  • Playlist tree assembly

This means that the iTunes XML importer will now display the playlist folder hierarchy as a tree too!

Architecture

flowchart LR

ITunesFeature -->|calls| ITunesImporter
ITunesImporter -->ITunesXMLImporter
ITunesImporter --> ITunesMacOSImporter
ITunesXMLImporter -->|calls| ITunesDAO
ITunesMacOSImporter -->|calls| ITunesDAO
Loading

While the new architecture might seem a bit verbose, we get a cleaner separation of concerns and can reduce the platform-specific code, which especially in the case of the macOS importer may improve maintainability too.

@Swiftb0y
Copy link
Member

This refactoring makes sense at first glance. I'll try to conduct a proper review in the near future. I'd suggest to call ITunesImportBackend ITunesPlaylistDAO or something since that seems to be its primary job, to be a Data Access Object.

@Swiftb0y
Copy link
Member

In the meantime, can you fix the clazy warnings?

@fwcd
Copy link
Member Author

fwcd commented Apr 21, 2023

I'd suggest to call ITunesImportBackend ITunesPlaylistDAO

In that case it should probably be ITunesDAO since it's responsible for tracks too, not just playlists.

src/library/itunes/itunesfeature.cpp Outdated Show resolved Hide resolved
src/library/itunes/itunesdao.h Outdated Show resolved Hide resolved
src/library/itunes/itunesdao.cpp Outdated Show resolved Hide resolved
src/library/itunes/itunesdao.cpp Outdated Show resolved Hide resolved
src/library/itunes/itunesfeature.cpp Outdated Show resolved Hide resolved
src/library/itunes/itunesmacosimporter.h Outdated Show resolved Hide resolved
src/library/itunes/itunesmacosimporter.mm Outdated Show resolved Hide resolved
fwcd and others added 4 commits April 25, 2023 00:17
Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM otherwise. I highly appreciate these refactoring PRs, even though they're probably in quite unused code.

src/library/itunes/itunesxmlimporter.cpp Outdated Show resolved Hide resolved
Comment on lines +48 to +49
virtual bool importTrack(const ITunesTrack& track);
virtual bool importPlaylist(const ITunesPlaylist& playlist);
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the fact that these have to be virtual just in order to be tested. Is there no feature in gtest that can avoid that using some linker hacks?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've thought about this and the other option would be to use templates and parameterize the importer over the DAO. Unfortunately, that would also mean that we'd have to move the implementation into headers etc.

Since virtual methods are generally not thaat expensive (I've tested it on a library with hundreds of playlists and >10k tracks with pretty much no noticeable performance difference), I think this should be fine. The database calls are likely more an order of magnitude more expensive than the virtual function calls.

Copy link
Member

Choose a reason for hiding this comment

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

Right, in the scope of everything else, those virtual calls are probably going to be cheap, I'm just used to them being expensive in the context of cache latency and branch prediction.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

LGTM, though I didn't conduct any manual tests

@Swiftb0y Swiftb0y merged commit dc5e69d into mixxxdj:2.4 Apr 25, 2023
@fwcd fwcd deleted the itunes-import-backend branch April 25, 2023 19:09
@fwcd fwcd added the itunes label Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants