Remove deep_rows query

Aim to fix sometimes slow moving of rows. Data from the 'deep' part is
no longer used anyway.

Fixes #258
This commit is contained in:
Keith Edmunds 2024-08-09 12:55:43 +01:00
parent 0bcb785b30
commit 42ebf2fa7b
2 changed files with 17 additions and 18 deletions

View File

@ -364,23 +364,6 @@ class PlaylistRows(dbtables.PlaylistRowsTable):
return session.execute(stmt).unique().scalar_one() 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 @staticmethod
def delete_higher_rows(session: Session, playlist_id: int, maxrow: int) -> None: def delete_higher_rows(session: Session, playlist_id: int, maxrow: int) -> None:
""" """
@ -486,6 +469,22 @@ class PlaylistRows(dbtables.PlaylistRowsTable):
return plrs 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 @classmethod
def get_rows_with_tracks( def get_rows_with_tracks(
cls, cls,

View File

@ -991,7 +991,7 @@ class PlaylistModel(QAbstractTableModel):
# Populate self.playlist_rows with playlist data # Populate self.playlist_rows with playlist data
self.playlist_rows.clear() 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) self.playlist_rows[p.row_number] = RowAndTrack(p)
def refresh_row(self, session, row_number): def refresh_row(self, session, row_number):