WIP folded get_filtered_tracks into repository
This commit is contained in:
parent
f9c060b091
commit
a160473d9e
@ -738,6 +738,9 @@ class Tracks(dbtables.TracksTable):
|
||||
Return tracks matching filter
|
||||
"""
|
||||
|
||||
# Now implemented in repostory.py
|
||||
return []
|
||||
|
||||
query = select(cls)
|
||||
|
||||
# Path specification
|
||||
|
||||
@ -231,19 +231,14 @@ class QuerylistModel(QAbstractTableModel):
|
||||
try:
|
||||
results = repository.get_filtered_tracks(self.filter)
|
||||
for result in results:
|
||||
lastplayed = None
|
||||
if hasattr(result, "playdates"):
|
||||
pds = result.playdates
|
||||
if pds:
|
||||
lastplayed = max([a.lastplayed for a in pds])
|
||||
queryrow = QueryRow(
|
||||
artist=result.artist,
|
||||
bitrate=result.bitrate or 0,
|
||||
duration=result.duration,
|
||||
lastplayed=lastplayed,
|
||||
lastplayed=result.lastplayed,
|
||||
path=result.path,
|
||||
title=result.title,
|
||||
track_id=result.id,
|
||||
track_id=result.track_id,
|
||||
)
|
||||
|
||||
self.querylist_rows[row] = queryrow
|
||||
|
||||
@ -237,14 +237,11 @@ def get_all_tracks() -> list[TrackDTO]:
|
||||
return _tracks_where(Tracks.id > 0)
|
||||
|
||||
|
||||
def get_filtered_tracks(filter: Filter) -> list["Tracks"]:
|
||||
def get_filtered_tracks(filter: Filter) -> list[TrackDTO]:
|
||||
"""
|
||||
Return tracks matching filter
|
||||
"""
|
||||
|
||||
with db.Session() as session:
|
||||
return Tracks.get_filtered_tracks(session, filter)
|
||||
|
||||
query = select(Tracks)
|
||||
|
||||
# Path specification
|
||||
@ -304,10 +301,32 @@ def get_filtered_tracks(filter: Filter) -> list["Tracks"]:
|
||||
subquery.c.max_last_played < before
|
||||
)
|
||||
|
||||
results: list[TrackDTO] = []
|
||||
with db.Session() as session:
|
||||
records = session.scalars(query).unique().all()
|
||||
for record in records:
|
||||
if record.playdates:
|
||||
last_played = record.playdates[0].lastplayed
|
||||
else:
|
||||
last_played = None
|
||||
last_played
|
||||
dto = TrackDTO(
|
||||
artist=record.artist,
|
||||
bitrate=record.bitrate,
|
||||
duration=record.duration,
|
||||
fade_at=record.fade_at,
|
||||
intro=record.intro,
|
||||
lastplayed=last_played,
|
||||
path=record.path,
|
||||
silence_at=record.silence_at,
|
||||
start_gap=record.start_gap,
|
||||
title=record.title,
|
||||
track_id=record.id,
|
||||
)
|
||||
results.append(dto)
|
||||
|
||||
return results
|
||||
|
||||
return records
|
||||
|
||||
@log_call
|
||||
def add_track_to_header(playlistrow_id: int, track_id: int) -> None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user