1
0
mirror of https://github.com/bspeice/Melodia synced 2024-12-25 08:08:13 -05:00

Minor optimization of archive scanning

This commit is contained in:
Bradlee Speice 2012-12-22 23:18:17 -05:00
parent 190f9a7890
commit 22bbc568e7

View File

@ -51,6 +51,13 @@ class Archive (models.Model):
_regex = '|'.join(( '.*' + ext + '$' for ext in SUPPORTED_AUDIO_EXTENSIONS)) _regex = '|'.join(( '.*' + ext + '$' for ext in SUPPORTED_AUDIO_EXTENSIONS))
regex = re.compile(_regex, re.IGNORECASE) 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 #Add new songs
for dirname, dirnames, filenames in os.walk(self.root_folder): for dirname, dirnames, filenames in os.walk(self.root_folder):
#For each filename #For each filename
@ -68,13 +75,6 @@ class Archive (models.Model):
new_song.save() new_song.save()
self.songs.add(new_song) 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): 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" "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 #This method operates only on the songs that are in the database - if you need to make