caching order fix for models fast load

This commit is contained in:
Billy 2025-10-02 19:26:53 +00:00
parent 93b73c9678
commit f4dd259cb4

View File

@ -96,7 +96,7 @@ class MusicTable(QTableView):
# need a QStandardItemModel to load data & do actions on cells # need a QStandardItemModel to load data & do actions on cells
self.model2: QStandardItemModel = QStandardItemModel() self.model2: QStandardItemModel = QStandardItemModel()
self.proxymodel: QSortFilterProxyModel = QSortFilterProxyModel() self.proxymodel: QSortFilterProxyModel = QSortFilterProxyModel()
self.cache_models: dict[int | None, QStandardItemModel] self.cache_models: dict[int | None, QStandardItemModel] = {}
self.search_string: str | None = None self.search_string: str | None = None
self.headers = HeaderTags() self.headers = HeaderTags()
# db names of headers # db names of headers
@ -734,9 +734,8 @@ class MusicTable(QTableView):
try: try:
new_model = self.cache_models[self.selected_playlist_id] new_model = self.cache_models[self.selected_playlist_id]
self.model2 = new_model self.model2 = new_model
debug('Cached model loaded')
except KeyError: except KeyError:
# Store the current loaded model
self.cache_models[self.selected_playlist_id] = self.model2
# Query for a playlist # Query for a playlist
if is_playlist: if is_playlist:
debug('load music table a playlist') debug('load music table a playlist')
@ -806,6 +805,10 @@ class MusicTable(QTableView):
for item in items: for item in items:
item.setData(id, Qt.ItemDataRole.UserRole) item.setData(id, Qt.ItemDataRole.UserRole)
self.model2.appendRow(items) self.model2.appendRow(items)
# Store the current loaded model
self.cache_models[self.selected_playlist_id] = self.model2
debug('Current model stored')
# reloading the model destroys and makes new indexes # reloading the model destroys and makes new indexes
# so we look for the new index of the current song on load # so we look for the new index of the current song on load