From c07bef0db1e630d8a8203d78d69ce87cc9985af1 Mon Sep 17 00:00:00 2001 From: sbuser Date: Mon, 8 Aug 2011 18:26:10 -0500 Subject: [PATCH] Keep a local cache of releaseID->releaseGroupID relationships so we don't hammer MB unnecessarily when external programs addReleaseByID --- headphones/__init__.py | 1 + headphones/importer.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index 6939f8b8..47e8ed29 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -431,6 +431,7 @@ def dbcheck(): c.execute('CREATE TABLE IF NOT EXISTS have (ArtistName TEXT, AlbumTitle TEXT, TrackNumber TEXT, TrackTitle TEXT, TrackLength TEXT, BitRate TEXT, Genre TEXT, Date TEXT, TrackID TEXT)') c.execute('CREATE TABLE IF NOT EXISTS lastfmcloud (ArtistName TEXT, ArtistID TEXT, Count INTEGER)') c.execute('CREATE TABLE IF NOT EXISTS descriptions (ReleaseGroupID TEXT, ReleaseID TEXT, Summary TEXT, Content TEXT)') + c.execute('CREATE TABLE IF NOT EXISTS releases (ReleaseID TEXT, ReleaseGroupID TEXT, UNIQUE(ReleaseID, ReleaseGroupID))') try: c.execute('SELECT IncludeExtras from artists') diff --git a/headphones/importer.py b/headphones/importer.py index 4f8dae3b..cfcd22ee 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -256,21 +256,26 @@ def addArtisttoDB(artistid, extrasonly=False): logger.info(u"Updating complete for: " + artist['artist_name']) def addReleaseById(rid): - + myDB = db.DBConnection() + + rgid = myDB.select("SELECT * from releases WHERE ReleaseID=?", [rid]) + if not rgid: + #we have to make a call to get the release no matter what so we can get the RGID + #need a way around this - a local cache maybe in the future maybe? + try: + release_dict = mb.getRelease(rid) + #keep a local cache of these so that external programs that are adding releasesByID don't hammer MB + myDB.action('INSERT INTO releases VALUES( ?, ?)', [rid, release_dict['rgid']]) + except Exception, e: + logger.info('Unable to get release information for Release: ' + str(rid) + " " + str(e)) + return + if not release_dict: + logger.info('Unable to get release information for Release: ' + str(rid) + " no dict") + return + + rgid = release_dict['rgid'] - #we have to make a call to get the release no matter what so we can get the RGID - #need a way around this - a local cache maybe in the future maybe? - try: - release_dict = mb.getRelease(rid) - except Exception, e: - logger.info('Unable to get release information for Release: ' + str(rid) + " " + str(e)) - return - if not release_dict: - logger.info('Unable to get release information for Release: ' + str(rid) + " no dict") - return - - rgid = release_dict['rgid'] #we don't want to make more calls to MB here unless we have to, could be happening quite a lot #TODO: why do I have to str() this here? I don't get it. @@ -316,7 +321,7 @@ def addReleaseById(rid): for track in release_dict['tracks']: controlValueDict = {"TrackID": track['id'], - "AlbumID": release_dict['rgid']} + "AlbumID": rgid} newValueDict = {"ArtistID": release_dict['artist_id'], "ArtistName": release_dict['artist_name'], "AlbumTitle": release_dict['rg_title'],