Improve performance of save_playlist
This commit is contained in:
parent
784d036bb7
commit
be4f19757c
@ -593,6 +593,27 @@ class PlaylistRows(Base):
|
|||||||
.values(row_number=PlaylistRows.row_number + move_by)
|
.values(row_number=PlaylistRows.row_number + move_by)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def indexed_by_row(session: Session, playlist_id: int) -> dict:
|
||||||
|
"""
|
||||||
|
Return a dictionary of playlist_rows indexed by row number for
|
||||||
|
the passed playlist_id.
|
||||||
|
"""
|
||||||
|
|
||||||
|
plrs = session.execute(
|
||||||
|
select(PlaylistRows)
|
||||||
|
.where(
|
||||||
|
PlaylistRows.playlist_id == playlist_id,
|
||||||
|
)
|
||||||
|
.order_by(PlaylistRows.row_number)
|
||||||
|
).scalars().all()
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
for plr in plrs:
|
||||||
|
result[plr.row_number] = plr
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class Settings(Base):
|
class Settings(Base):
|
||||||
"""Manage settings"""
|
"""Manage settings"""
|
||||||
|
|||||||
@ -827,11 +827,11 @@ class PlaylistTab(QTableWidget):
|
|||||||
the row number is correct (in case tracks have been reordered).
|
the row number is correct (in case tracks have been reordered).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
plr_dict = PlaylistRows.indexed_by_row(session, self.playlist_id)
|
||||||
for row in range(self.rowCount()):
|
for row in range(self.rowCount()):
|
||||||
plr = session.get(PlaylistRows, self._get_playlistrow_id(row))
|
|
||||||
# Set the row number and playlist id (even if correct)
|
# Set the row number and playlist id (even if correct)
|
||||||
plr.row_number = row
|
plr_dict[row].row_number = row
|
||||||
plr.playlist_id = self.playlist_id
|
plr_dict[row].playlist_id = self.playlist_id
|
||||||
|
|
||||||
# Any rows in the database with a row_number higher that the
|
# Any rows in the database with a row_number higher that the
|
||||||
# current value of 'row' should not be there. Commit session
|
# current value of 'row' should not be there. Commit session
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user