From 42ebf2fa7bfd8cf607766184c1521f86fbf71538 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 9 Aug 2024 12:55:43 +0100 Subject: [PATCH] Remove deep_rows query Aim to fix sometimes slow moving of rows. Data from the 'deep' part is no longer used anyway. Fixes #258 --- app/models.py | 33 ++++++++++++++++----------------- app/playlistmodel.py | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/models.py b/app/models.py index 81d3f01..cedbc7e 100644 --- a/app/models.py +++ b/app/models.py @@ -364,23 +364,6 @@ class PlaylistRows(dbtables.PlaylistRowsTable): return session.execute(stmt).unique().scalar_one() - @classmethod - def deep_rows(cls, session: Session, playlist_id: int) -> Sequence["PlaylistRows"]: - """ - Return a list of playlist rows that include full track and lastplayed data for - given playlist_id., Sequence - """ - - stmt = ( - select(PlaylistRows) - .options(joinedload(cls.track)) - .where(PlaylistRows.playlist_id == playlist_id) - .order_by(PlaylistRows.row_number) - # .options(joinedload(Tracks.playdates)) - ) - - return session.scalars(stmt).unique().all() - @staticmethod def delete_higher_rows(session: Session, playlist_id: int, maxrow: int) -> None: """ @@ -486,6 +469,22 @@ class PlaylistRows(dbtables.PlaylistRowsTable): return plrs + @classmethod + def get_playlist_rows( + cls, session: Session, playlist_id: int + ) -> Sequence["PlaylistRows"]: + """ + For passed playlist, return a list of rows. + """ + + plrs = session.scalars( + select(cls) + .where(cls.playlist_id == playlist_id) + .order_by(cls.row_number) + ).all() + + return plrs + @classmethod def get_rows_with_tracks( cls, diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 4a2cc19..76f3e53 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -991,7 +991,7 @@ class PlaylistModel(QAbstractTableModel): # Populate self.playlist_rows with playlist data self.playlist_rows.clear() - for p in PlaylistRows.deep_rows(session, self.playlist_id): + for p in PlaylistRows.get_playlist_rows(session, self.playlist_id): self.playlist_rows[p.row_number] = RowAndTrack(p) def refresh_row(self, session, row_number):