performance of playlistinfo <id> and status not dependent on playlist length
This commit is contained in:
parent
c7207c3d85
commit
fab020f2d0
@ -1,6 +1,7 @@
|
||||
from copy import copy
|
||||
import logging
|
||||
import random
|
||||
import pprint
|
||||
|
||||
from mopidy.listeners import BackendListener
|
||||
from mopidy.models import CpTrack
|
||||
@ -28,6 +29,7 @@ class CurrentPlaylistController(object):
|
||||
|
||||
Read-only.
|
||||
"""
|
||||
logger.debug(u'current_playlist.cp_tracks')
|
||||
return [copy(ct) for ct in self._cp_tracks]
|
||||
|
||||
@property
|
||||
@ -37,8 +39,16 @@ class CurrentPlaylistController(object):
|
||||
|
||||
Read-only.
|
||||
"""
|
||||
logger.debug(u'current_playlist.tracks()')
|
||||
return [ct[1] for ct in self._cp_tracks]
|
||||
|
||||
@property
|
||||
def tracks_len(self):
|
||||
"""
|
||||
Length of current playlist
|
||||
"""
|
||||
return len(self._cp_tracks)
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""
|
||||
|
||||
@ -254,6 +254,12 @@ def playlistinfo(context, songpos=None,
|
||||
end = songpos + 1
|
||||
if start == -1:
|
||||
end = None
|
||||
else:
|
||||
#Fetch one single track, hot code path (avoid deep-copying the entire playlist)
|
||||
res = context.backend.current_playlist.get(cpid=songpos).get()
|
||||
cpids = [res.cpid]
|
||||
l = [res.track]
|
||||
return tracks_to_mpd_format(l, 0, 1, cpids=cpids)
|
||||
cpids = [ct[0] for ct in
|
||||
context.backend.current_playlist.cp_tracks.get()]
|
||||
return tracks_to_mpd_format(
|
||||
|
||||
@ -166,7 +166,7 @@ def status(context):
|
||||
decimal places for millisecond precision.
|
||||
"""
|
||||
futures = {
|
||||
'current_playlist.tracks': context.backend.current_playlist.tracks,
|
||||
'current_playlist.tracks_len': context.backend.current_playlist.tracks_len,
|
||||
'current_playlist.version': context.backend.current_playlist.version,
|
||||
'mixer.volume': context.mixer.volume,
|
||||
'playback.consume': context.backend.playback.consume,
|
||||
@ -213,7 +213,7 @@ def _status_consume(futures):
|
||||
return 0
|
||||
|
||||
def _status_playlist_length(futures):
|
||||
return len(futures['current_playlist.tracks'].get())
|
||||
return futures['current_playlist.tracks_len'].get()
|
||||
|
||||
def _status_playlist_version(futures):
|
||||
return futures['current_playlist.version'].get()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user