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

DB: Fix 0/NULL issues when reading source_synchronized_ms #4012

Merged
merged 7 commits into from
Jun 17, 2021
Merged

DB: Fix 0/NULL issues when reading source_synchronized_ms #4012

merged 7 commits into from
Jun 17, 2021

Conversation

uklotzde
Copy link
Contributor

@uklotzde uklotzde commented Jun 17, 2021

Unfortunately I noticed a very strange behavior of Qt when reading a nullable integer database column that contains NULL:

// Observation (Qt 5.15): QVariant::isValid() may return true even
// if the column value is NULL and then converts to 0 (zero). This
// is NOT desired and therefore we MUST USE QVariant::isNull() instead!

As a consequence the column library.source_synchronized_ms now contains 0 (= zero) instead of NULL for some tracks after they have been loaded and saved at least once after the migration.

Do we need a formal DB schema update to fix this issue? This would probably be the safe solution.

The first commit is just a minor logging improvement to detect inconsistencies between the library and external files.

@uklotzde uklotzde added this to the 2.4.0 milestone Jun 17, 2021
@uklotzde uklotzde requested a review from daschuer June 17, 2021 12:47
@uklotzde
Copy link
Contributor Author

I have added the schema migration.

For extra safety the value 0 is no longer valid, because it indicates a bogus value.

...even though the edge is already handled before and will never occur.
@Holzhaus
Copy link
Member

For extra safety the value 0 is no longer valid, because it indicates a bogus value.

What if I last modified my file on January 1st, 1970?😁

Seriously though, from time to time I've seem those kind of file modification times, probably because some other software was buggy. Would that cause any undesired behavior?

@poelzi
Copy link
Contributor

poelzi commented Jun 17, 2021

All files in the nix store are defaulted to that modified time if you don't set it to something specific

-r-xr-xr-x 1 root root 1495112 Jan  1  1970 /nix/store/lz515dc98y93x2srr0gq50zzsiwbffh8-sqlite-3.33.0-bin/bin/sqlite3

It could be that somebody nixifies his music collection ;)

@uklotzde
Copy link
Contributor Author

All files in the nix store are defaulted to that modified time if you don't set it to something specific

-r-xr-xr-x 1 root root 1495112 Jan  1  1970 /nix/store/lz515dc98y93x2srr0gq50zzsiwbffh8-sqlite-3.33.0-bin/bin/sqlite3

It could be that somebody nixifies his music collection ;)

Just one more reason to ignore this time stamp and treat it as NULL, i.e. unknown.

@uklotzde
Copy link
Contributor Author

If the file modification time doesn't reflect a valid time then it should be ignored. That's what this PR does besides fixing the actual bug.

@uklotzde
Copy link
Contributor Author

It would be dangerous if we add logic on top of useless data. If you don't time stamp your files properly you will simply not be able to use the extended metadata synchronization. That's safe and fair.

@uklotzde
Copy link
Contributor Author

I must admit that I didn't think about the 0 edge case. In the end the occurrence of this bug was actually helpful to discover and resolve it early before it could do any harm 😅

@@ -151,8 +151,12 @@ void exportMetadata(djinterop::database* pDatabase,
snapshot.comment = pTrack->getComment().toStdString();
snapshot.composer = pTrack->getComposer().toStdString();
snapshot.key = toDjinteropKey(pTrack->getKey());
int64_t lastModifiedMillisSinceEpoch =
pTrack->getFileInfo().lastModified().toMSecsSinceEpoch();
int64_t lastModifiedMillisSinceEpoch = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mr-smidge I fixed a possible edge case

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, thank you 👍

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you.

@daschuer daschuer merged commit 207043d into mixxxdj:main Jun 17, 2021
@uklotzde uklotzde deleted the source_synchronized_ms branch June 17, 2021 22:32
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.

5 participants