-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 library track selection, save model state #4177
Conversation
4b98db8
to
10bda6b
Compare
Alrighty, I think this is now in a good shape. While debugging a crash I noticed that
Apart from that it works great! @ywwg Feel free to build the header functions on top (sort order, individual headers etc.) |
10bda6b
to
79a6d8f
Compare
right now the commit history still contains a lot of back and forth experiments. |
287d72f
to
a1427f8
Compare
I'm splitting the overall final changes into easily digestible bits, so don't start reviewing, yet. |
a1427f8
to
4966ec3
Compare
Please fix the conflicts for testing. |
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.
Thank you for picking this up.
I have added som suggestions, not found real issues. I will do also a manual test soon.
src/library/basesqltablemodel.cpp
Outdated
if (noSearch) { | ||
return QStringLiteral("table:") + m_tableName; | ||
} | ||
return QStringLiteral("table:") + m_tableName + |
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.
The same here.
We also may consider to move this function into the base class and fetch only the prefix via an overloaded virtual function.
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, the modelKey() function is identical for most models, except Browse, Crate, BaseExternalPlaylistModel and Proxy..
So I wonder if it's worth the effort.
Fo rmy taste it's optimized sufficiently if the model prefix becomes a const in the namespaces.
VERIFY_OR_DEBUG_ASSERT(!key.isEmpty()) { | ||
return; | ||
} | ||
ModelState* state = m_modelStateCache.take(key); |
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 think we can use .object() her which keeps the state object int the cache but moves it to the top.
If it returns null we can immediately insert the new element.
This avoids to move the ownership of the created object around and is probably a bit faster.
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.
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 one is open. I think we should use the normal pattern for QCache here unless we can remember the reason and put that into the code.
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 follow the logic that the Object in the QCache is only ever owned by one owner, rust style. It is either in the update handler or in the QCache object, but it is never in the update handler while the QCache thinks it needs to drop this object.
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.
See the warning in the QCache docs, if you just get a pointer:
Warning: The returned object is owned by QCache and may be deleted at any time.
If I remember correctly, I could provoke a crash by very fast switching between different models, I was able to cause a crash.
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. could you add a review/code suggestion that adds a comment with this explanation?
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.
The Warning applies applies, if you store the pointer in a member variable, or if we use the cache from multiple threads.
The QCrash has no magic to do something at laterally any time. It can do something at any call.
All this does not apply here. So I am not able to write a reasonable comment. I assume the crashes was cased by something else.
However since this is only a minor issue, and not on a performance critic path, I think we should keep this tested variant, but not add a comment with probably wrong assumptions.
I have just give this a brief test. I think it works like it should from the code, but it does not feel correct. Let's say I select a track "Nickelblack". This not a regression here, but I like to know if you can confirm it. |
yes. with that commit it is decided if a search term is a reduced search, aka, is less sepecific. In this case, the selected track will be in the selection and therefor should keep it's selection. This felt correct when testing. |
If reviews of the current state don't bring any issues to light I can continue to pick more of @poelzi's commits to improve the situation further. Though, I'll have to delve into the search parser stuff to somewhat know what I'm doing, and debug issues I ran into during previous attempts. |
I would prefer to merge this soon and go in smaller steps. This has no regression to main so it should be possible. The QCache usage is open and the CI failure. |
re CI failure |
Is there anything left to do here? |
adding a comment explaining why the state is taken from the QHash, populated and re-inserted afterwards. |
ping @daschuer |
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.
LGTM,
Thank you @ronso0 for picking it up.
VERIFY_OR_DEBUG_ASSERT(!key.isEmpty()) { | ||
return; | ||
} | ||
ModelState* state = m_modelStateCache.take(key); |
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.
The Warning applies applies, if you store the pointer in a member variable, or if we use the cache from multiple threads.
The QCrash has no magic to do something at laterally any time. It can do something at any call.
All this does not apply here. So I am not able to write a reasonable comment. I assume the crashes was cased by something else.
However since this is only a minor issue, and not on a performance critic path, I think we should keep this tested variant, but not add a comment with probably wrong assumptions.
🎉 |
This is an attempt to cherry-pick commits from @poelzi's #3063 to fix the library track selection only
(save/restore selection, focus and scroll position per model view).
I guess this will take some time due to short free time, some merge conflicts, building each commit etc.
TODO
noSearch
parameter