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

Bug: remember library sorting #947

Merged
merged 13 commits into from May 21, 2016
Merged

Bug: remember library sorting #947

merged 13 commits into from May 21, 2016

Conversation

jmigual
Copy link
Contributor

@jmigual jmigual commented May 11, 2016

Resolves https://bugs.launchpad.net/mixxx/+bug/1474098

Now the BaseSqlTableModel remembers the hierarchical sorting across restarts

@@ -21,7 +21,7 @@
#include "util/assert.h"
#include "util/performancetimer.h"

static const bool sDebug = false;
static const bool sDebug = true;
Copy link
Member

Choose a reason for hiding this comment

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

Please keep this one off since it produces a ton of verbose logging.

@daschuer
Copy link
Member

Travis fails unrelated to this PR:

The job exceeded the maxmimum time limit for jobs, and has been terminated.

@@ -139,6 +139,23 @@ class BaseSqlTableModel : public QAbstractTableModel, public TrackModel {
}
int m_column;
Qt::SortOrder m_order;

friend QTextStream& operator >> (QTextStream &in, SortColumn &sc) {
Copy link
Member

@rryan rryan May 11, 2016

Choose a reason for hiding this comment

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

Storing the columns as integers means we can't make changes to the column orderings in the future since they are stored in user databases. Could you store them as column names instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'll change that

Copy link
Member

Choose a reason for hiding this comment

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

I am afraid we hit a conceptual issue. :-/
The current solution is a simple serialize without ans sanity checks. The same we have with the header state.
Since this is not that critical data, that "could" work as it is, including all issues we already heave.
If not, we should should probably ditch the SettingsDAO entirely and move to mixxx.cfg, which allows us to parse and check the values before using. .. and is human readable.
@jmigual and @rryan: What do you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But if we save the column name as a string this should solve the problem. It is true that there are no sanity checks but this can only be a problem if we change the name or remove a column that the user has previously sorted but once she tries to sort again and restarts mixxx the problem solves (when I changed from integers to strings I had this problem and I forced sorting and restarted and then it worked fine again)

Copy link
Member

Choose a reason for hiding this comment

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

I am afraid we hit a conceptual issue. :-/
The current solution is a simple serialize without ans sanity checks. The same we have with the header state.

Since this is not that critical data, that "could" work as it is, including all issues we already heave.

I would prefer to treat user data as "sacred" -- if we decide to save something we should save it in a future-proof manner or not save it at all :).

If not, we should should probably ditch the SettingsDAO entirely and move to mixxx.cfg, which allows us to parse and check the values before using. .. and is human readable.

SettingsDAO and mixxx.cfg don't seem any different in this regard, are they? You can store any QString / QByteArray in either of them. It's up to the code that reads/stores to it to parse/check.

We could use a protocol buffer to serialize column sort state -- we could store that in either mixxx.cfg or SettingsDAO and we would get parsing, serializing and the ability to migrate users to a future format easily. Human readability can be achieved with protobuf text formatting but I'm not sure if it needs to be human readable?

Copy link
Member

Choose a reason for hiding this comment

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

Before this PR SettingsDAO has serialized data which where likely misinterpreted after an update and mixxx.cfg has human readable and editable data. I like the idea to treat the data as "sacred", but we don't do this with the header state.

Right -- header data is opaque since we can't really tell what Qt is storing in there (well, we could but we don't). So we rely on Qt to correctly save/restore it.

Do you mean that the header data already contains sorting state so there's the possibility for this PR to store data conflicting with the header state?

What will be the rule of thump, which storage is used when?

I agree conceptually it's awkward to have two different places to store key/value configuration data. I think the rule of thumb is that the library settings table is for storing library-specific configuration data. It's nice that a user can copy their mixxxdb.sqlite to a different profile and still have a working library. So things like the current schema version absolutely have to go in SettingsDAO, but things like the preferred column sort order is less clear-cut. I'd be OK with the rule of thumb being "all library-specific preferences go in the library settings table".

Copy link
Member

Choose a reason for hiding this comment

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

Ok. that sounds reasonable.

Do you mean that the header data already contains sorting state so there's the possibility for this PR to store data conflicting with the header state?

No, because we need here the sorting hierarchy.

Copy link
Member

Choose a reason for hiding this comment

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

@jmigual: Would you mind to put this rule of thump as comment into

mixxx/src/library/dao/settingsdao.h

Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done

Copy link
Member

Choose a reason for hiding this comment

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

we can't really tell what Qt is storing in there

I thought I rewrote the header-saving code and got rid of the old QT-binary blob? So that upgrading is easier.

@rryan
Copy link
Member

rryan commented May 11, 2016

Travis fails unrelated to this PR:

The job exceeded the maxmimum time limit for jobs, and has been terminated.

Yea I think I caused this when I enabled asan on Travis builds for OS X. I think we should make the tests run faster -- they take almost a minute on my machine.

@rryan
Copy link
Member

rryan commented May 11, 2016

Travis fails unrelated to this PR:

The job exceeded the maxmimum time limit for jobs, and has been terminated.
Yea I think I caused this when I enabled asan on Travis builds for OS X. I think we should make the tests run faster -- they take almost a minute on my machine.

I reverted my asan commit.

}

friend QTextStream & operator << (QTextStream &out, SortColumn &sc) {
out << sc.m_column << " ";
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why we have here a space and not in the reading code above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because QTextStream skips spaces when reading but you need to set spaces when writing (like it happens normally in cin and cout)

QString name;

in >> name >> ordI;
int col = this->fieldIndex(name) + m_tableColumns.size() - 1;
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 redundant

@daschuer
Copy link
Member

With this patch it happens, that the table is emptied.
When I click on the preview coloumn thhan cover than artist,
the track table is empty
When I click on album and artist, it comes back.
Could this be related to the -1 column issue?

@jmigual
Copy link
Contributor Author

jmigual commented May 12, 2016

Yes it is related to the -1 column issue, I'll fix it now. By the way how can you view this with mixxx?

VALUES ("mixxx.db.model.playlist.ColumnsSorting"," 1 -1 -1 ","0","0");

@daschuer
Copy link
Member

I use the Firefox SqLite Manager Add-on


QString name;
if (sc.m_column > 0 && sc.m_column < m_tableColumns.size()) {
name = m_tableColumns[column];
Copy link
Member

Choose a reason for hiding this comment

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

Typo?
name = m_tableColumns[sc.m_column];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's a typo, I'll change it now

// Write new sortColumns order to user settings
QString val;
QTextStream out(&val);
qDebug() << m_tableColumns;
Copy link
Member

Choose a reason for hiding this comment

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

This seams to be an intermediate debug. Remove?

@daschuer
Copy link
Member

Thank you. There is only a single debug leftover and than LGTM.
(Note: Since GitHub does not notify us for new commits, please leave a comment every time you wish a review)

@jmigual
Copy link
Contributor Author

jmigual commented May 20, 2016

Ok, fixed. I didn't know GitHub does not notify users so I'll take into account.

@daschuer
Copy link
Member

Thank you :-)

@daschuer daschuer merged commit 4008e11 into mixxxdj:master May 21, 2016
@jmigual jmigual deleted the bug/rememberLibrarySorting branch May 23, 2016 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants