From 6e3b374dcbe8788bf3db2007cdb12d3f48160f58 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Tue, 19 Feb 2013 16:45:58 +0100 Subject: [PATCH] only load genre/style/mood from cache if it is empty --- .../dynamic/echonest/EchonestGenerator.cpp | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index d6aea73b2..ca4a87aef 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -615,40 +615,48 @@ EchonestGenerator::loadStylesMoodsAndGenres() { if( !s_styles.isEmpty() && !s_moods.isEmpty() && !s_genres.isEmpty() ) return; - - QVariant styles = TomahawkUtils::Cache::instance()->getData( "EchonesGenerator", "styles" ); - if ( styles.isValid() && styles.canConvert< QStringList >() ) + if ( s_styles.isEmpty() ) { - s_styles = styles.toStringList(); - } - else - { - tLog() << "Styles not in cache or too old, refetching styles ..."; - s_stylesJob = Echonest::Artist::listTerms( "style" ); - connect( s_stylesJob, SIGNAL( finished() ), this, SLOT( stylesReceived() ) ); + QVariant styles = TomahawkUtils::Cache::instance()->getData( "EchonesGenerator", "styles" ); + if ( styles.isValid() && styles.canConvert< QStringList >() ) + { + s_styles = styles.toStringList(); + } + else + { + tLog() << "Styles not in cache or too old, refetching styles ..."; + s_stylesJob = Echonest::Artist::listTerms( "style" ); + connect( s_stylesJob, SIGNAL( finished() ), this, SLOT( stylesReceived() ) ); + } } - QVariant moods = TomahawkUtils::Cache::instance()->getData( "EchonesGenerator", "moods" ); - if ( moods.isValid() && moods.canConvert< QStringList >() ) { - s_moods = moods.toStringList(); - } - else + if ( s_moods.isEmpty() ) { - tLog() << "Moods not in cache or too old, refetching moods ..."; - s_moodsJob = Echonest::Artist::listTerms( "mood" ); - connect( s_moodsJob, SIGNAL( finished() ), this, SLOT( moodsReceived() ) ); + QVariant moods = TomahawkUtils::Cache::instance()->getData( "EchonesGenerator", "moods" ); + if ( moods.isValid() && moods.canConvert< QStringList >() ) { + s_moods = moods.toStringList(); + } + else + { + tLog() << "Moods not in cache or too old, refetching moods ..."; + s_moodsJob = Echonest::Artist::listTerms( "mood" ); + connect( s_moodsJob, SIGNAL( finished() ), this, SLOT( moodsReceived() ) ); + } } - QVariant genres = TomahawkUtils::Cache::instance()->getData( "EchonesGenerator", "genres" ); - if ( genres.isValid() && genres.canConvert< QStringList >() ) + if ( s_genres.isEmpty() ) { - s_genres = genres.toStringList(); - } - else - { - tLog() << "Genres not in cache or too old, refetching genres ..."; - s_genresJob = Echonest::Artist::fetchGenres(); - connect( s_genresJob, SIGNAL( finished() ), this, SLOT( genresReceived() ) ); + QVariant genres = TomahawkUtils::Cache::instance()->getData( "EchonesGenerator", "genres" ); + if ( genres.isValid() && genres.canConvert< QStringList >() ) + { + s_genres = genres.toStringList(); + } + else + { + tLog() << "Genres not in cache or too old, refetching genres ..."; + s_genresJob = Echonest::Artist::fetchGenres(); + connect( s_genresJob, SIGNAL( finished() ), this, SLOT( genresReceived() ) ); + } } }