mirror of
https://github.com/beetbox/beets.git
synced 2026-02-24 16:23:04 +01:00
simplifications afforded by eager result iterators (#261)
This commit is contained in:
parent
bcc348f018
commit
d805401b23
2 changed files with 8 additions and 23 deletions
|
|
@ -137,15 +137,11 @@ def _item_duplicate_check(lib, task, recent=None):
|
|||
recent.add((artist, title))
|
||||
|
||||
# Check the library.
|
||||
item_iter = lib.items(artist=artist, title=title)
|
||||
try:
|
||||
for other_item in item_iter:
|
||||
# Existing items not considered duplicates.
|
||||
if other_item.path == task.item.path:
|
||||
continue
|
||||
return True
|
||||
finally:
|
||||
item_iter.close()
|
||||
for other_item in lib.items(artist=artist, title=title):
|
||||
# Existing items not considered duplicates.
|
||||
if other_item.path == task.item.path:
|
||||
continue
|
||||
return True
|
||||
return False
|
||||
|
||||
def _infer_album_fields(task):
|
||||
|
|
@ -489,14 +485,12 @@ def query_tasks(config):
|
|||
|
||||
if config.singletons:
|
||||
# Search for items.
|
||||
items = list(lib.items(config.query))
|
||||
for item in items:
|
||||
for item in lib.items(config.query):
|
||||
yield ImportTask.item_task(item)
|
||||
|
||||
else:
|
||||
# Search for albums.
|
||||
albums = lib.albums(config.query)
|
||||
for album in albums:
|
||||
for album in lib.albums(config.query):
|
||||
log.debug('yielding album %i: %s - %s' %
|
||||
(album.id, album.albumartist, album.album))
|
||||
items = list(album.items())
|
||||
|
|
@ -613,9 +607,7 @@ def apply_choices(config):
|
|||
# last item is removed.
|
||||
replaced_items = defaultdict(list)
|
||||
for item in items:
|
||||
dup_items = list(lib.items(
|
||||
library.MatchQuery('path', item.path)
|
||||
))
|
||||
dup_items = lib.items(library.MatchQuery('path', item.path))
|
||||
for dup_item in dup_items:
|
||||
replaced_items[item].append(dup_item)
|
||||
log.debug('replacing item %i: %s' % (dup_item.id, item.path))
|
||||
|
|
|
|||
|
|
@ -510,11 +510,6 @@ class ResultIterator(object):
|
|||
row = self.rowiter.next() # May raise StopIteration.
|
||||
return Item(row)
|
||||
|
||||
def close(self):
|
||||
# No longer used. Previously, this method would close the
|
||||
# cursor, but this is not necessary with the eager design.
|
||||
pass
|
||||
|
||||
|
||||
# An abstract library.
|
||||
|
||||
|
|
@ -1032,8 +1027,6 @@ class Library(BaseLibrary):
|
|||
return it.next()
|
||||
except StopIteration:
|
||||
return None
|
||||
finally:
|
||||
it.close()
|
||||
|
||||
def get_album(self, item_or_id):
|
||||
"""Given an album ID or an item associated with an album,
|
||||
|
|
|
|||
Loading…
Reference in a new issue