Skip to content

BaseSqlTableModel: disable undesirable sorting#4735

Closed
davidchocholaty wants to merge 2 commits intomixxxdj:mainfrom
davidchocholaty:fix_undesirable_tracks_sorting
Closed

BaseSqlTableModel: disable undesirable sorting#4735
davidchocholaty wants to merge 2 commits intomixxxdj:mainfrom
davidchocholaty:fix_undesirable_tracks_sorting

Conversation

@davidchocholaty
Copy link
Copy Markdown
Contributor

@davidchocholaty davidchocholaty commented Apr 28, 2022

Fixes undesirable tracks sorting in tables.
The mentioned situation could have occurred if the star rating
was changed for some tracks and then after the action
of removing tracks, adding tracks or filtering, the tracks
were sorted.

So, when removing tracks now tracks are kept at the same position
for a user. With adding tracks the new tracks are added at the end
of the tracks table. The automatic sorting is kept when it is changed
between track tables, for example between crates and tracks.

Fixes: lp:1387373 "Remove a track from a crate triggers sorting"
Reported by: Jean Claveau

davidchocholaty and others added 2 commits April 28, 2022 13:14
This commit fixes undesirable tracks sorting in tables.
The mentioned situation could have occurred, if the stars rating
was changed for some tracks and then after the action
of removing tracks, adding tracks or filtering, the tracks
were sorted.

So, when removing tracks now tracks are kept at the same position
for a user. With adding tracks the new tracks are added at the end
of the tracks table. The automatic sorting is kept when it is changed
between track tables, for example between crates and tracks.

Fixes: #1387373 ("Remove a track from a crate triggers sorting")
Reported-by: Jean Claveau
@ronso0
Copy link
Copy Markdown
Member

ronso0 commented Apr 29, 2022

Thank you for working on this issue!

Does this bug occur in Mixxx 2.3.2? If so, the fix should go to the 2.3 branch. Please rebase and force-push.

@uklotzde
Copy link
Copy Markdown
Contributor

uklotzde commented Apr 29, 2022

Thank you for working on this issue!

Does this bug occur in Mixxx 2.3.2? If so, the fix should go to the 2.3 branch. Please rebase and force-push.

Such a massivemajor and risky change is not supposed to go into a bugfix release.

@ronso0
Copy link
Copy Markdown
Member

ronso0 commented Apr 29, 2022

Thank you for working on this issue!
Does this bug occur in Mixxx 2.3.2? If so, the fix should go to the 2.3 branch. Please rebase and force-push.

Such a massivemajor and risky change is not supposed to go into a bugfix release.

Oh wow, I didn't look at the change set.
You're totally right.

@daschuer
Copy link
Copy Markdown
Member

daschuer commented May 3, 2022

Thank you for this not that easy first PR. It took me a while to wrap my head around it.

It solves the issue, but for my understanding it needs some tweaks. I have found two remaining issues:

  • After dropping a file to a playlist, another random file is selected.
  • Dropped files into a crate are now sorted in the end, which is out of sight for a big crate. A feedback is missing if the file is now part of the crate or not.

I think we should either resort after dropping a file, or place it where it was dropped.

Copy link
Copy Markdown
Contributor

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

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

This PR doesn't work for me. Search results are not updated as expected when modifying the query.

I am also concerned about storing even more data in memory.

}

if (!m_sortedTracksIndexes.isEmpty()) {
if (trackIds.size() < m_sortedTracksIndexes.size()) {
Copy link
Copy Markdown
Contributor

@uklotzde uklotzde May 3, 2022

Choose a reason for hiding this comment

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

These assumptions are wrong. An arbitrary number of tracks could be added or removed. Even if the size didn't change then the number of additions equals the number of removals. That's all you could deduce.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just want to make sure I understand the problem correctly. My solution do these comparisons to find out if tracks were removed or added by the last sorted tracks. As you said, it is possible to remove and add the same count of tracks, I agree, but in my opinion, removing tracks and adding tracks will be done by separated method calls and it could not be done together. Or am I wrong?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Making assumptions about such arbitrary preconditions is incorrect. The invocation of select() doesn't guarantee any of those.

qDebug() << "Rows actually received:" << rowInfos.size();
}

if (!m_sortedTracksIndexes.isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we get rid of this whole block, if we just use a vector of tracks?
Removed tracks are simply missing and skipped when sorting.
New tracks are missing and can be sorted in by the code for dirty tracks.
For a visual feedback it would be nice to either scroll to the dropped track or place it just where it was dropped, which requires even more refactoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it would be possible, I'll take a look at it.

} else {
// Loop through tracks and store their indexes
// from the previous sorted order.
while (query.next()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If sortedIndexes would be a vector we can just loop over it and assign the sorting value consecutive if found.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR doesn't work for me. Search results are not updated as expected when modifying the query.

I am also concerned about storing even more data in memory.

You are right, that it is a little bit problematic because more memory has to be used. Anyway, I couldn't find out another solution because it is necessary to store sorted tracks order. While tracks are chosen in filterAndSort() method it is necessary to have available the previous sorted order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If sortedIndexes would be a vector we can just loop over it and assign the sorting value consecutive if found.

Ok, I'll try to remake it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you.

Some Ideas regarding the extra memory of redundant data:

I think we can safely reuse QVector BaseSqlTableModel::m_rowInfo which holds the old sorting and is used to implement the QAbstractTableModel interface.

BaseTrackCache::m_trackOrder this was original a local variable from BaseTrackCache::filterAndSort() made a class member to keep the allocated memory for later calls, this has changed content due to the shared nature of BaseTrackCache. Maybe we can also get rid of this ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the tips. Sounds good to me. I will try what will be possible asap. I agree, that adding this new feature can be a little bit problematic with wasting memory or data duplication in some ways.

@github-actions
Copy link
Copy Markdown

This PR is marked as stale because it has been open 90 days with no activity.

@github-actions github-actions Bot added the stale Stale issues that haven't been updated for a long time. label Aug 22, 2022
@daschuer daschuer marked this pull request as draft August 22, 2022 06:41
@github-actions github-actions Bot removed the stale Stale issues that haven't been updated for a long time. label Aug 23, 2022
@ronso0
Copy link
Copy Markdown
Member

ronso0 commented Apr 19, 2026

I think the issue has finally been fixed by #15872


I'll close this abandoned PR now to clean up the list of open PRs.
If the author or mainatiners think this should remain open please reopen.
If anyone thinks this is worth salvaging and is motivated to pick it up, resolve the conflicts and move it forward, feel free to open a new PR.

@ronso0 ronso0 closed this Apr 19, 2026
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.

4 participants