Temp changes for profiling

This commit is contained in:
Keith Edmunds 2024-12-05 17:42:46 +00:00
parent 2c19981cd8
commit 17ab9c1c65

View File

@ -92,7 +92,7 @@ class PlaylistModel(QAbstractTableModel):
# Ensure row numbers in playlist are contiguous
PlaylistRows.fixup_rownumbers(session, playlist_id)
# Populate self.playlist_rows
self.refresh_data(session)
self.load_data(session)
self.update_track_times()
def __repr__(self) -> str:
@ -811,8 +811,10 @@ class PlaylistModel(QAbstractTableModel):
self.update_track_times()
self.invalidate_rows(list(row_map.keys()))
@line_profiler.profile
def move_rows_between_playlists(
self, from_rows: list[int], to_row_number: int, to_playlist_id: int
self, from_rows: list[int], to_row_number: int, to_playlist_id: int,
dummy_for_profiling=None
) -> None:
"""
Move the playlist rows given to to_row and below of to_playlist.
@ -1010,6 +1012,33 @@ class PlaylistModel(QAbstractTableModel):
# Copy to self.playlist_rows
self.playlist_rows = new_playlist_rows
# Same as refresh data, but only used when creating playslit.
# Distinguishes profile time between initial load and other
# refreshes.
def load_data(self, session: db.session, dummy_for_profiling=None) -> None:
"""Populate self.playlist_rows with playlist data"""
# We used to clear self.playlist_rows each time but that's
# expensive and slow on big playlists
# Note where each playlist_id is
plid_to_row: dict[int, int] = {}
for oldrow in self.playlist_rows:
plrdata = self.playlist_rows[oldrow]
plid_to_row[plrdata.playlistrow_id] = plrdata.row_number
# build a new playlist_rows
new_playlist_rows: dict[int, RowAndTrack] = {}
for p in PlaylistRows.get_playlist_rows(session, self.playlist_id):
if p.id not in plid_to_row:
new_playlist_rows[p.row_number] = RowAndTrack(p)
else:
new_playlist_rows[p.row_number] = self.playlist_rows[plid_to_row[p.id]]
new_playlist_rows[p.row_number].row_number = p.row_number
# Copy to self.playlist_rows
self.playlist_rows = new_playlist_rows
def refresh_row(self, session, row_number):
"""Populate dict for one row from database"""