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
VLCMediaLibraryManager: Basic migration of MLLabels and MLFiles #135
Conversation
9fd7bff
to
7b0a18f
Compare
Updated new VLCMediaLibraryKit changes. |
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 |
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.
can we do it without that hack?
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.
It won't work without it, we do need the real path for the medialibrary , it's the ugly solution I found for it.
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.
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
Are you talking about the setup in |
self.migrateToNewMediaLibrary() | ||
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true, completion: nil) | ||
} | ||
UIApplication.shared.keyWindow?.rootViewController?.present(migrationViewController, animated: true, completion: nil) |
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.
This code belongs into a viewcontroller, preferrably on the rootviewcontroller
} | ||
|
||
for media in allFiles { | ||
if let migratedMedia = fetchMedia(with: realPath(to: media.url)) { |
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.
can you have a media without url and the case that fetchMedia fails is not handled
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.
A media needs to have an mrl, if it doesn't then it cannot be migrated.
return | ||
} | ||
|
||
for media in allFiles { |
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.
can we rename it to oldMedia and newMedia?
} | ||
|
||
for label in allLabels { | ||
var mediaForPlaylist = [VLCMLMedia]() |
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.
shouldn't that media already exist or is this the playlist?
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.
Not sure to understand what you mean here.
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.
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) |
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.
newPlaylist
Sources/VLCAppDelegate.m
Outdated
@@ -84,6 +82,25 @@ + (void)initialize | |||
[defaults registerDefaults:appDefaults]; | |||
} | |||
|
|||
- (void)setup | |||
{ | |||
void (^setupLibraryBlock)(void) = ^{ |
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.
can we update the name setupLibraryBlock ?
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.
Yes we can~
@@ -269,7 +242,7 @@ - (void)applicationWillResignActive:(UIApplication *)application | |||
|
|||
- (void)applicationDidBecomeActive:(UIApplication *)application | |||
{ | |||
if (!_isRunningMigration && !_isComingFromHandoff) { | |||
if (!_isComingFromHandoff) { |
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.
why did you remove this and why is it not handled anymore?
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 don't think we need it anymore, do you see a need for this bool?
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.
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
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.
Yes but if I'm not mistaken, we don't migrate the old medialibrary anymore.
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.
that's true but shouldn't we update here the new Medialibrary and metadata and only do that if we're not migrating?
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 don't think we need to update the new Medialibrary here, I might be missing some cases?
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.
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.
f69f218
to
16a1573
Compare
348bbcb
to
5237e1c
Compare
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.
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.
- 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.
- 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 |
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.
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 | ||
} |
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.
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) { |
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.
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") |
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.
why is this a developer failure ? wouldn't that happen when there are no folders in a library?
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.
No.
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.
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) { |
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.
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
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.
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
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.
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.
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.
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.
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.
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 { |
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.
could you even just call migrationViewController.dismiss ?
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.
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) |
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.
it fails for me here with "error: value of type 'VLCMLMedia' has no member 'setPlayCount'"
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.
Yes, you need a fresh build of the wrapper, I didn't release the update it yet.
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.
should we also set the Metadata field "Seen" here ?
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.
Yes, we definitely could, but it's should be more or less implicit with the play count if it's correctly set.
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.
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.
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.
Sorry, I planned on doing it but I completely forgot about it! It should be all good now. 👍
okay just need the new wrapper and also set the seen metadata field as well :) Everything else looks good to me! |
5237e1c
to
86522be
Compare
Rebased and removed the ugly realpath hack! 🎉 |
okay then just the new Medialib and the isseen flag and we can merge \o/ |
aa11bf8
to
5b50845
Compare
Rebased, re-tested and made CircleCI happy! 🎉 |
VLCMigrationViewController: Remove completionHandler AppDelegate: Remove migration related code
5b50845
to
bb5599e
Compare
Checklist
bundle exec fastlane test
from the root directory to see all new and existing tests passbundle exec fastlane lint
to ensure the code style is validDescription
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.