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

VLCMediaLibraryManager: Basic migration of MLLabels and MLFiles #135

Merged
merged 5 commits into from Nov 19, 2018

Conversation

Mikanbu
Copy link
Member

@Mikanbu Mikanbu commented Aug 29, 2018

Checklist

  • I've run bundle exec fastlane test from the root directory to see all new and existing tests pass
  • I've followed the vlc-ios code style and run bundle exec fastlane lint to ensure the code style is valid
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Description

Basic migration of MLLabels and MLFiles.

Small note: This need a fresh build of VLCMediaLibraryKit to work since the changes haven't been released yet.

@Mikanbu Mikanbu added the WIP Work in Progress label Aug 29, 2018
@Mikanbu Mikanbu removed the WIP Work in Progress label Aug 30, 2018
@Mikanbu Mikanbu force-pushed the medialibrary/migration/initial branch 2 times, most recently from 9fd7bff to 7b0a18f Compare September 3, 2018 09:25
@Mikanbu
Copy link
Member Author

Mikanbu commented Sep 3, 2018

Updated new VLCMediaLibraryKit changes.

@carolanitz
Copy link
Member

can you move the migration out of didFinishlaunchingWithoptions or make sure that that method returns fast enough. The App gets killed if we take too long (like 20 to 30 secs) can you also check if the users kills the app during migration that you don't have duplicates?

// MARK: - Migration

private extension VLCMediaLibraryManager {
// Ugly hack to get the realPath
Copy link
Member

@carolanitz carolanitz Sep 3, 2018

Choose a reason for hiding this comment

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

can we do it without that hack?

Copy link
Member Author

@Mikanbu Mikanbu Sep 3, 2018

Choose a reason for hiding this comment

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

It won't work without it, we do need the real path for the medialibrary , it's the ugly solution I found for it.

Copy link
Member

Choose a reason for hiding this comment

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

we need the real path only because the fix to adjust it to a relative path hasn't made it yet into the medialibrary correct?If so can we should push for that to be fixed

@Mikanbu
Copy link
Member Author

Mikanbu commented Sep 3, 2018

Are you talking about the setup in didFinishlaunchingWithOptions ?

self.migrateToNewMediaLibrary()
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true, completion: nil)
}
UIApplication.shared.keyWindow?.rootViewController?.present(migrationViewController, animated: true, completion: nil)
Copy link
Member

Choose a reason for hiding this comment

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

This code belongs into a viewcontroller, preferrably on the rootviewcontroller

}

for media in allFiles {
if let migratedMedia = fetchMedia(with: realPath(to: media.url)) {
Copy link
Member

Choose a reason for hiding this comment

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

can you have a media without url and the case that fetchMedia fails is not handled

Copy link
Member Author

Choose a reason for hiding this comment

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

A media needs to have an mrl, if it doesn't then it cannot be migrated.

SharedSources/VLCMediaLibraryManager.swift Outdated Show resolved Hide resolved
SharedSources/VLCMediaLibraryManager.swift Outdated Show resolved Hide resolved
return
}

for media in allFiles {
Copy link
Member

Choose a reason for hiding this comment

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

can we rename it to oldMedia and newMedia?

}

for label in allLabels {
var mediaForPlaylist = [VLCMLMedia]()
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't that media already exist or is this the playlist?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure to understand what you mean here.

Copy link
Member

Choose a reason for hiding this comment

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

is this a playlist? or is this media that gets added to a Playlist? the title suggest the second and if so this should already exist and just be retrieved to be added to the newly created playlist

mediaForPlaylist.append(migratedMedia)
}
}
let migratedPlaylist = createPlaylist(with: label.name)
Copy link
Member

Choose a reason for hiding this comment

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

newPlaylist

@@ -84,6 +82,25 @@ + (void)initialize
[defaults registerDefaults:appDefaults];
}

- (void)setup
{
void (^setupLibraryBlock)(void) = ^{
Copy link
Member

Choose a reason for hiding this comment

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

can we update the name setupLibraryBlock ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we can~

@@ -269,7 +242,7 @@ - (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (!_isRunningMigration && !_isComingFromHandoff) {
if (!_isComingFromHandoff) {
Copy link
Member

Choose a reason for hiding this comment

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

why did you remove this and why is it not handled anymore?

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 don't think we need it anymore, do you see a need for this bool?

Copy link
Member

@carolanitz carolanitz Sep 3, 2018

Choose a reason for hiding this comment

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

do you understand why it was here? the code in the next line causes access to the medialibrary which would crash the entire application if the Medialibrary was being migrated

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but if I'm not mistaken, we don't migrate the old medialibrary anymore.

Copy link
Member

@carolanitz carolanitz Sep 3, 2018

Choose a reason for hiding this comment

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

that's true but shouldn't we update here the new Medialibrary and metadata and only do that if we're not migrating?

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 don't think we need to update the new Medialibrary here, I might be missing some cases?

Copy link
Member

Choose a reason for hiding this comment

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

okay so when files were deleted while the App was not running the mediadatabase handles it automatically right? This used to be also the point where we would adjust the searchable index to remove and add deleted or added files but do we move that somewhere else then? In that case it might make sense to remove the old updateMediaDatabase call and VLCMediaFileDiscoverer code as well. Additionally since we're not accessing the mediadatabase from recoverDisplayedMetadata( at least from what I can see) we don't need the check for _isComingFromhandoff.

@Mikanbu Mikanbu force-pushed the medialibrary/migration/initial branch 2 times, most recently from f69f218 to 16a1573 Compare September 3, 2018 12:18
@Mikanbu Mikanbu added the WIP Work in Progress label Sep 3, 2018
@Mikanbu Mikanbu force-pushed the medialibrary/migration/initial branch from 348bbcb to 5237e1c Compare September 5, 2018 13:04
@Mikanbu Mikanbu removed the WIP Work in Progress label Sep 6, 2018
Copy link
Member

@carolanitz carolanitz left a comment

Choose a reason for hiding this comment

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

Migrations are hard, there are lots of things to consider and we don't want to mess up users files or they will hate us so I'm a bit anal here. This iteration is already better. There are still a couple of things that need to be double checked.

  1. that there is no code that would access the Medialib while it is migrating. This can happen if you open the app through "Open in" or openURL, or click on a CSSearchable Item or force touch the vlc icon, or or or.
  2. test all combinations that a user can have with the migration to make sure everything works correctly. Only files, files and folders, folders with mixed media, only episodes or albumtracks, empty folders, only folders and so on.

// MARK: - Migration

private extension VLCMediaLibraryManager {
// Ugly hack to get the realPath
Copy link
Member

Choose a reason for hiding this comment

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

we need the real path only because the fix to adjust it to a relative path hasn't made it yet into the medialibrary correct?If so can we should push for that to be fixed

return true
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

don't we need the result to not access the medialibrary while we migrate?

@@ -269,7 +242,7 @@ - (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (!_isRunningMigration && !_isComingFromHandoff) {
if (!_isComingFromHandoff) {
Copy link
Member

Choose a reason for hiding this comment

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

okay so when files were deleted while the App was not running the mediadatabase handles it automatically right? This used to be also the point where we would adjust the searchable index to remove and add deleted or added files but do we move that somewhere else then? In that case it might make sense to remove the old updateMediaDatabase call and VLCMediaFileDiscoverer code as well. Additionally since we're not accessing the mediadatabase from recoverDisplayedMetadata( at least from what I can see) we don't need the check for _isComingFromhandoff.

// Note: This removes **only** files that are in a playlist
func migratePlaylists(_ oldMedialibrary: MLMediaLibrary) -> Bool {
guard let allLabels = MLLabel.allLabels() as? [MLLabel] else {
assertionFailure("VLCMediaLibraryManager: Migration: Unable to retreive all labels")
Copy link
Member

Choose a reason for hiding this comment

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

why is this a developer failure ? wouldn't that happen when there are no folders in a library?

Copy link
Member Author

Choose a reason for hiding this comment

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

No.

Copy link
Member

Choose a reason for hiding this comment

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

Ah when you have no folders this method returns an empty array so this case would not happen. For some reason I thought this could return nil

return false
}

if migrateMedia(oldMedialibrary) && migratePlaylists(oldMedialibrary) {
Copy link
Member

Choose a reason for hiding this comment

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

these calls should not be done on the mainthread because that would block the UI. the migration should be dispatched to a background thread so that the activityspinner can spin when we show the migrationcontroller

Copy link
Member

Choose a reason for hiding this comment

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

Also if you return false for migratePlaylists when there are no folders in someones library you would always do a migration correct and never mark it as migrated

Copy link
Member Author

Choose a reason for hiding this comment

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

Also if you return false for migratePlaylists when there are no folders in someones library you would always do a migration correct and never mark it as migrated

Not sure how that could happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

these calls should not be done on the mainthread because that would block the UI.

I agree, but if I'm not mistaken they are not in the main thread since it launched on the didCompleteDiscovery thread.

Copy link
Member

Choose a reason for hiding this comment

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

ah nice! I just double checked and in that case we're okay for the userdefaults since they're threadsafe but I would dispatch the delegate calls back to the mainthread because you do UI work. It does work though without mainthread checker warnings which is surprising for me

}

func medialibraryDidFinishMigration(_ medialibrary: VLCMediaLibraryManager) {
if tabBarController.presentedViewController === migrationViewController {
Copy link
Member

Choose a reason for hiding this comment

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

could you even just call migrationViewController.dismiss ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly to double check but I could.

for media in allFiles {
if let newMedia = fetchMedia(with: realPath(to: media.url)) {
newMedia.updateTitle(media.title)
newMedia.setPlayCount(media.playCount.uint32Value)
Copy link
Member

Choose a reason for hiding this comment

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

it fails for me here with "error: value of type 'VLCMLMedia' has no member 'setPlayCount'"

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you need a fresh build of the wrapper, I didn't release the update it yet.

Copy link
Member

Choose a reason for hiding this comment

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

should we also set the Metadata field "Seen" here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we definitely could, but it's should be more or less implicit with the play count if it's correctly set.

Copy link
Member

Choose a reason for hiding this comment

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

you're right, that it is implicit but we will forget that at some point and just check for for the isSeen flag. For the new tag for example and we claim this media was never seen so it would show it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I planned on doing it but I completely forgot about it! It should be all good now. 👍

@carolanitz
Copy link
Member

okay just need the new wrapper and also set the seen metadata field as well :) Everything else looks good to me!

@Mikanbu
Copy link
Member Author

Mikanbu commented Oct 7, 2018

Rebased and removed the ugly realpath hack! 🎉
A fresh VLCMediaLibraryKit is needed, 0.0.7 doesn't include realpath changes

@carolanitz
Copy link
Member

okay then just the new Medialib and the isseen flag and we can merge \o/

@Mikanbu Mikanbu force-pushed the medialibrary/migration/initial branch from aa11bf8 to 5b50845 Compare November 19, 2018 14:29
@Mikanbu
Copy link
Member Author

Mikanbu commented Nov 19, 2018

Rebased, re-tested and made CircleCI happy! 🎉
Waiting for a last review to merge.

@Mikanbu Mikanbu force-pushed the medialibrary/migration/initial branch from 5b50845 to bb5599e Compare November 19, 2018 15:21
@vlc-mirrorer vlc-mirrorer merged commit bb5599e into videolan:master Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants