mirror of
				https://github.com/bspeice/Melodia
				synced 2025-11-04 02:10:42 -05:00 
			
		
		
		
	Minor optimization of archive scanning
This commit is contained in:
		@ -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
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user