No db calls when servicing data() except for caching
This commit is contained in:
parent
85493de179
commit
963da0b5d0
@ -109,7 +109,7 @@ class NoteColours(dbtables.NoteColoursTable):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_colour(
|
def get_colour(
|
||||||
session: Session, text: str, foreground: bool = False
|
session: Session, text: str, foreground: bool = False
|
||||||
) -> Optional[str]:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Parse text and return background (foreground if foreground==True) colour
|
Parse text and return background (foreground if foreground==True) colour
|
||||||
string if matched, else None
|
string if matched, else None
|
||||||
@ -117,7 +117,7 @@ class NoteColours(dbtables.NoteColoursTable):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not text:
|
if not text:
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
match = False
|
match = False
|
||||||
for rec in NoteColours.get_all(session):
|
for rec in NoteColours.get_all(session):
|
||||||
@ -138,10 +138,10 @@ class NoteColours(dbtables.NoteColoursTable):
|
|||||||
|
|
||||||
if match:
|
if match:
|
||||||
if foreground:
|
if foreground:
|
||||||
return rec.foreground
|
return rec.foreground or ""
|
||||||
else:
|
else:
|
||||||
return rec.colour
|
return rec.colour
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
def invalidate_cache(self) -> None:
|
def invalidate_cache(self) -> None:
|
||||||
"""Invalidate dogpile cache"""
|
"""Invalidate dogpile cache"""
|
||||||
|
|||||||
@ -439,6 +439,12 @@ class RowAndTrack:
|
|||||||
self.row_number = playlist_row.row_number
|
self.row_number = playlist_row.row_number
|
||||||
self.track_id = playlist_row.track_id
|
self.track_id = playlist_row.track_id
|
||||||
|
|
||||||
|
# Playlist display data
|
||||||
|
self.row_fg: Optional[str] = None
|
||||||
|
self.row_bg: Optional[str] = None
|
||||||
|
self.note_fg: Optional[str] = None
|
||||||
|
self.note_bg: Optional[str] = None
|
||||||
|
|
||||||
# Collect track data if there's a track
|
# Collect track data if there's a track
|
||||||
if playlist_row.track_id:
|
if playlist_row.track_id:
|
||||||
self.artist = playlist_row.track.artist
|
self.artist = playlist_row.track.artist
|
||||||
|
|||||||
@ -70,8 +70,11 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
database.
|
database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, playlist_id: int, is_template: bool,) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
playlist_id: int,
|
||||||
|
is_template: bool,
|
||||||
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
log.debug("PlaylistModel.__init__()")
|
log.debug("PlaylistModel.__init__()")
|
||||||
@ -182,12 +185,13 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
# Header row
|
# Header row
|
||||||
if self.is_header_row(row):
|
if self.is_header_row(row):
|
||||||
# Check for specific header colouring
|
# Check for specific header colouring
|
||||||
with db.Session() as session:
|
if rat.row_bg is None:
|
||||||
note_background = NoteColours.get_colour(session, rat.note)
|
with db.Session() as session:
|
||||||
if note_background:
|
rat.row_bg = NoteColours.get_colour(session, rat.note)
|
||||||
return QBrush(QColor(note_background))
|
if rat.row_bg:
|
||||||
else:
|
return QBrush(QColor(rat.row_bg))
|
||||||
return QBrush(QColor(Config.COLOUR_NOTES_PLAYLIST))
|
else:
|
||||||
|
return QBrush(QColor(Config.COLOUR_NOTES_PLAYLIST))
|
||||||
# Unreadable track file
|
# Unreadable track file
|
||||||
if file_is_unreadable(rat.path):
|
if file_is_unreadable(rat.path):
|
||||||
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
||||||
@ -219,10 +223,11 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
return QBrush(QColor(Config.COLOUR_BITRATE_OK))
|
return QBrush(QColor(Config.COLOUR_BITRATE_OK))
|
||||||
if column == Col.NOTE.value:
|
if column == Col.NOTE.value:
|
||||||
if rat.note:
|
if rat.note:
|
||||||
with db.Session() as session:
|
if rat.note_bg is None:
|
||||||
note_background = NoteColours.get_colour(session, rat.note)
|
with db.Session() as session:
|
||||||
if note_background:
|
rat.note_bg = NoteColours.get_colour(session, rat.note)
|
||||||
return QBrush(QColor(note_background))
|
if rat.note_bg:
|
||||||
|
return QBrush(QColor(rat.note_bg))
|
||||||
|
|
||||||
return QBrush()
|
return QBrush()
|
||||||
|
|
||||||
@ -1575,13 +1580,11 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
if not track_id:
|
if not track_id:
|
||||||
return ""
|
return ""
|
||||||
playdates = Playdates.last_playdates(session, track_id)
|
playdates = Playdates.last_playdates(session, track_id)
|
||||||
return (
|
return "<br>".join(
|
||||||
"<br>".join(
|
[
|
||||||
[
|
a.lastplayed.strftime(Config.LAST_PLAYED_TOOLTIP_DATE_FORMAT)
|
||||||
a.lastplayed.strftime(Config.LAST_PLAYED_TOOLTIP_DATE_FORMAT)
|
for a in playdates
|
||||||
for a in playdates
|
]
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_or_insert(self, track_id: int, row_number: int) -> None:
|
def update_or_insert(self, track_id: int, row_number: int) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user