From 22bbc568e7d2bdbfcf0780a6501bc45aaa4e6516 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sat, 22 Dec 2012 23:18:17 -0500 Subject: [PATCH] Minor optimization of archive scanning --- archiver/archive.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/archiver/archive.py b/archiver/archive.py index 23ece56..c649fba 100644 --- a/archiver/archive.py +++ b/archiver/archive.py @@ -51,6 +51,13 @@ class Archive (models.Model): _regex = '|'.join(( '.*' + ext + '$' for ext in SUPPORTED_AUDIO_EXTENSIONS)) regex = re.compile(_regex, re.IGNORECASE) + #Remove songs in the database if they exist no longer + # -Do this first since we don't need to re-check songs that were just added + for song in self.songs.all(): + if not os.path.isfile(song.url): + song.delete() + continue + #Add new songs for dirname, dirnames, filenames in os.walk(self.root_folder): #For each filename @@ -68,13 +75,6 @@ class Archive (models.Model): new_song.save() self.songs.add(new_song) - #Remove songs in the database if they exist no longer - for song in self.songs.all(): - if not os.path.isfile(song.url): - song.delete() - continue - - def _update_song_metadata(self, use_echonest = False, progress_callback = lambda x, y: None): "Scan every song in this archive (database only) and make sure all songs are correct" #This method operates only on the songs that are in the database - if you need to make