diff --git a/headphones/importer.py b/headphones/importer.py index ca8c8134..c933e656 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -59,6 +59,11 @@ def artistlist_to_mbids(artistlist, forced=False): except Exception, e: logger.warn('Failed to update arist information from Last.fm: %s' % e) +def addArtistIDListToDB(artistidlist): + # Used to add a list of artist IDs to the database in a single thread + logger.debug("Importer: Adding artist ids %s" % artistidlist) + for artistid in artistidlist: + addArtisttoDB(artistid) def addArtisttoDB(artistid, extrasonly=False): diff --git a/headphones/webserve.py b/headphones/webserve.py index 0522b0c1..2338be4b 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -211,6 +211,7 @@ class WebInterface(object): def markArtists(self, action=None, **args): myDB = db.DBConnection() + artistsToAdd = [] for ArtistID in args: if action == 'delete': myDB.action('DELETE from artists WHERE ArtistID=?', [ArtistID]) @@ -225,9 +226,10 @@ class WebInterface(object): newValueDict = {'Status': 'Active'} myDB.upsert("artists", newValueDict, controlValueDict) else: - # These may and probably will collide - need to make a better way to queue musicbrainz queries - threading.Thread(target=importer.addArtisttoDB, args=[ArtistID]).start() - time.sleep(30) + artistsToAdd.append(ArtistID) + if len(artistsToAdd) > 0: + logger.debug("Refreshing artists: %s" % artistsToAdd) + threading.Thread(target=importer.addArtistIDListToDB, args=[artistsToAdd]).start() raise cherrypy.HTTPRedirect("home") markArtists.exposed = True