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

Fix detection of moved tracks #2197

Merged
merged 13 commits into from
Jul 7, 2019
Merged

Fix detection of moved tracks #2197

merged 13 commits into from
Jul 7, 2019

Conversation

uklotzde
Copy link
Contributor

While working on the aoide integration I found multiple bugs in the algorithm and database queries for detecting moved tracks.

Please don't ask for additional tests (the current test apparently didn't reveal those bugs) or further refactoring. I will only provide this minimal set of changes and will not dedicate more time for this backport.

@uklotzde uklotzde added this to the 2.2.2 milestone Jun 30, 2019
@daschuer
Copy link
Member

Thank you for fixing this, this is itching me for long.
I think this is a 2.2 PR, do you agree?

@uklotzde
Copy link
Contributor Author

Yes, it works for both 2.2 and master.

The fixes should be straight forward by inspecting the individual commits. The wrong id parameter might only affect tracks that have already been moved, because the id counters from both tables are in lockstep for newly added tracks (AUTOINCREMENT). Though I'm not sure how long this condition holds, it might break at any time!

@daschuer
Copy link
Member

The code looks good, I will do some tests.

@uklotzde
Copy link
Contributor Author

In the dev_aoide branch I have even eliminated some redundant queries. But I won't backport these improvements.

@uklotzde uklotzde changed the title Backport to 2.2: Fix detection of moved tracks [WiP] Backport to 2.2: Fix detection of moved tracks Jul 2, 2019
@uklotzde
Copy link
Contributor Author

uklotzde commented Jul 2, 2019

With the last commit I have backported all (relevant) changes from my feature branch. We can remove it if it is too complex for a bug fix of a release version.

@uklotzde uklotzde changed the title [WiP] Backport to 2.2: Fix detection of moved tracks Backport to 2.2: Fix detection of moved tracks Jul 2, 2019
<< newTrackLocation;
++newTrackLocationCount;
newTrackId = TrackId(newTrackQuery.value(
newTrackQuery.record().indexOf("track_id")));
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 move the indexOf() part to the top?
I think it is const among all queries.

src/library/dao/trackdao.cpp Show resolved Hide resolved
DEBUG_ASSERT(newTrackId.isValid());
DEBUG_ASSERT(newTrackLocationId.isValid());
kLogger.info()
<< "Found moved track location:"
Copy link
Member

Choose a reason for hiding this comment

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

Does this potentially join two tracks?
If we have a duplicate track and remove one?
Do we need some extra handling in this case?

<< newTrackLocation;
break;
default:
kLogger.warning()
Copy link
Member

Choose a reason for hiding this comment

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

This is the case we have tree duplicates and one disappears, or if we have duplicates and one is moved.
It would be nice to detect the move. In this case use the just added track.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this comment. All the new have just been added. If multiple of them are candidates for one missing track, we cannot make a decision.

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 possible case:

  • User has the same track in two folders.
  • He moved to a new library location.
  • He expects that the tracks are still OK

What will happen? I have not tested it yet.

I assume currently both tracks remain missing after the move and pointing to the old location. I think it is better to assign both duplicates to the first of the two moved tracks than break a playlist.

src/library/dao/trackdao.cpp Outdated Show resolved Hide resolved
// table which corresponds to the track in the new location. We need
// to remove that so we don't end up with two rows in the library
// table for the same track.
{
Copy link
Member

Choose a reason for hiding this comment

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

What is if we found a duplicate and the track was already part of playlists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The newly added track can safely be deleted, because it is not referenced in any playlist. The track that was marked as missing will become visible again after referencing the new, existing location.

Copy link
Member

Choose a reason for hiding this comment

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

But if we delete it here and something goes wrong below, the track is lost until the directory hash changes.

const int filenameColumn = queryRecord.indexOf("filename");
const int durationColumn = queryRecord.indexOf("duration");
QSqlQuery newTrackQuery(m_database);
newTrackQuery.prepare(QString(
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 to decide if this shall only detect newly added tracks or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we don't. At least not now. This is how the function was designed and I will not modify it.

Copy link
Member

Choose a reason for hiding this comment

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

OK.

// Should not happen!
VERIFY_OR_DEBUG_ASSERT(query.exec()) {
LOG_FAILED_QUERY(query);
// Last chance to skip this entry
Copy link
Member

Choose a reason for hiding this comment

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

Really? We have already deleted the new track above.

@daschuer
Copy link
Member

daschuer commented Jul 4, 2019

Nice solution :-)

@uklotzde
Copy link
Contributor Author

uklotzde commented Jul 4, 2019

If addedTracks is empty the algorithm might consider all tracks in the library instead of just returning. But I don't want to mess around with it now. This should be done as a separate task when adding such a new library maintenance feature.

@daschuer
Copy link
Member

daschuer commented Jul 4, 2019

LGTM, I just build it for a final test.
I think it should go to 2.2, right?

@uklotzde
Copy link
Contributor Author

uklotzde commented Jul 5, 2019

Backported for 2.2.

Both AppVeyour builds timed out, the Ubuntu build got stuck after ~27 min.

@ninomp
Copy link
Contributor

ninomp commented Jul 5, 2019

Backported for 2.2.

Hmm This PR is (still) targeting master branch. 😕

@uklotzde uklotzde changed the base branch from master to 2.2 July 5, 2019 12:53
@uklotzde
Copy link
Contributor Author

uklotzde commented Jul 5, 2019

Switched the target branch. Unfortunately that doesn't trigger a rebuild.

@uklotzde uklotzde changed the title Backport to 2.2: Fix detection of moved tracks Fix detection of moved tracks Jul 7, 2019
@daschuer
Copy link
Member

daschuer commented Jul 7, 2019

Still builds and works good. Thank you.

@daschuer daschuer merged commit ff98230 into mixxxdj:2.2 Jul 7, 2019
@daschuer
Copy link
Member

daschuer commented Jul 7, 2019

@uklotzde Can you merge 2.2 into master there is a conflict with the tests. Thanks.

@uklotzde uklotzde deleted the 2.2_fix_detection_of_moved_tracks branch July 21, 2019 11:09
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.

3 participants