Optimize rand_candidate
The set of searchable songs shouldn't change while selecting songs. We can determine which list of songs to look at up front and always use that as an argument to rand_candidate()
This commit is contained in:
parent
2cd2f4f742
commit
de31941af1
|
@ -77,19 +77,23 @@ def seq_next():
|
|||
cur_index += 1
|
||||
return song_list[cur_index]
|
||||
|
||||
def rand_candidate(max):
|
||||
def rand_candidate(list, max):
|
||||
index = rand.randint(0, max-1)
|
||||
if filtered == False:
|
||||
return song_list[index]
|
||||
return list(visible)[index]
|
||||
return list[index]
|
||||
|
||||
def rand_next():
|
||||
n = num_visible()
|
||||
if n == 0:
|
||||
return
|
||||
get_attrs = library.get_attrs
|
||||
|
||||
if filtered == False:
|
||||
selection = song_list
|
||||
else:
|
||||
selection = list(visible)
|
||||
|
||||
for i in xrange(15):
|
||||
id = rand_candidate(n)
|
||||
id = rand_candidate(selection, n)
|
||||
(artist, title, score) = get_attrs(id, "artist", "title", "score")
|
||||
if (artist, title) in recent:
|
||||
print recent_msg % (artist, title)
|
||||
|
|
Loading…
Reference in New Issue