Bug 213165

Summary: 100% cpu and no response when unfolding the unknown category in jamendo
Product: [Applications] amarok Reporter: Guido Schmidt <guido>
Component: Internet ServicesAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: major CC: dikmax, nhn
Priority: NOR Keywords: release_blocker
Version: 2.2.1   
Target Milestone: 2.2.2   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:

Description Guido Schmidt 2009-11-04 23:48:33 UTC
Version:            (using KDE 4.3.3)
OS:                Linux
Installed from:    openSUSE RPMs

Loaded plugins:
- amaroKnotify
- Ultimate Lyrics
- Cool Streams
- Librivox.org
- Radios Francaises
- Radios Portuguesas

Backtraces:
- None. Don't know how to get one when I have to manually kill the application.

How to Reproduce: 
- Open Internet > Jamendo.com
- Click on the arrow next to the category named "unknown" to open it
- Watch the guitar-symbol change to two-arrows-in-a-circle. It is not rotating. One CPU-core goes to 100%. At this time amarok is still working for a while.
- After a while (a minute or maybe less) it only needs one more click or even just waiting and amarok freezes.
- The behavior remains the same when all plugins are disabled.

Expected Behaviour:
- Show the contents of the unknown category.
Comment 1 Myriam Schweingruber 2009-11-05 00:00:59 UTC
And what exact Amarok version are you talking about?
Comment 2 Guido Schmidt 2009-11-05 00:05:40 UTC
That's funny. While filling out the bug report I chose the version from a drop-down-list. Don't know why it didn't make into the report.

Anyway, version is 2.2.0.
Comment 3 Myriam Schweingruber 2009-11-05 00:07:50 UTC
Added to the filed now, thx.
Comment 4 Myriam Schweingruber 2009-11-26 14:49:05 UTC
Can somebody reproduce this with current Amarok 2.2.1 or Amarok 2.2-git?
Comment 5 Guido Schmidt 2009-11-26 22:11:58 UTC
I can. Version is 2.2.1. 
BTW: With the UI already frozen playback continues until the current title ends.

Setting it to unconfirmed. If this is not the desired status please let me know. (Couldn't find any documentation about that. If there is any I would be grateful if someone could point me to it.)
Comment 6 Myriam Schweingruber 2009-11-26 22:14:35 UTC
Thanks for the prompt feedback, we need another confirmation though, since you are the original reporter.
Comment 7 Maxim Dikun 2009-12-03 14:35:26 UTC
I can confirm this bug. I'm using Amarok 2.2.1 on KDE 4.3.4

And it uses 100% CPU because Amarok read something from hard disk. iotop shows throughput ~60M/s all time.
Comment 8 Myriam Schweingruber 2009-12-03 15:14:30 UTC
Thanks for the feedback.
Comment 9 Nikolaj Hald Nielsen 2009-12-16 14:02:50 UTC
commit 0ffe80bbd8fe074dea64abb985a413885a1ab765
Author: Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
Date:   Wed Dec 16 13:04:00 2009 +0100

    Prune out any genres with empty names or the name "Unknown" when importing the Jamendo database.
    This gets rid of the "Unknown" genre at the top of the lsit that freezes Amarok when you try to expand it.
    Some albums might be filtered out by this, but a) these were not accessible anyway and b) if the album has not been tagged with even a single genre by the artist, then it is r
    BUG: 213165
Comment 10 Nikolaj Hald Nielsen 2009-12-17 06:17:27 UTC
commit 0ffe80bbd8fe074dea64abb985a413885a1ab765
Author: Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
Date:   Wed Dec 16 13:04:00 2009 +0100

    Prune out any genres with empty names or the name "Unknown" when importing the Jamendo database.
    This gets rid of the "Unknown" genre at the top of the lsit that freezes Amarok when you try to expand it.
    Some albums might be filtered out by this, but a) these were not accessible anyway and b) if the album has not been tagged with even a single genre by the artist, then it is really their own fault that their album does not get much exposure...
    BUG: 213165

diff --git a/src/services/ServiceSqlQueryMaker.cpp b/src/services/ServiceSqlQueryMaker.cpp
index 87a8bfd..0c01dfe 100644
--- a/src/services/ServiceSqlQueryMaker.cpp
+++ b/src/services/ServiceSqlQueryMaker.cpp
@@ -564,10 +564,13 @@ ServiceSqlQueryMaker::query()
 QStringList
 ServiceSqlQueryMaker::runQuery( const QString &query )
 {
+   DEBUG_BLOCK
    if( d->albumMode == OnlyCompilations )
        return QStringList();
 
-    return m_collection->query( query );
+   
+   debug() << "query: " << query;
+   return m_collection->query( query );
 }
 
 void
diff --git a/src/services/jamendo/JamendoXmlParser.cpp b/src/services/jamendo/JamendoXmlParser.cpp
index f6109e0..1584f1c 100644
--- a/src/services/jamendo/JamendoXmlParser.cpp
+++ b/src/services/jamendo/JamendoXmlParser.cpp
@@ -281,7 +281,7 @@ JamendoXmlParser::readAlbum()
     Q_ASSERT( m_reader.isStartElement() && m_reader.name() == "album" );
 
     //debug() << "Found album: ";
-    m_nNumberOfAlbums++;
+    
 
     QString name;
     QString genre;
@@ -322,25 +322,30 @@ JamendoXmlParser::readAlbum()
         }
     }
 
-    JamendoAlbum currentAlbum( name );
-    currentAlbum.setGenre( genre );
-    currentAlbum.setDescription( description );
-    currentAlbum.setId( m_currentAlbumId );
-    currentAlbum.setArtistId( m_currentArtistId );
-    currentAlbum.setLaunchYear( releaseDate.left( 4 ).toInt() );
-    currentAlbum.setCoverUrl( COVERURL_BASE.arg( m_currentAlbumId ) );
-    currentAlbum.setMp3TorrentUrl( TORRENTURL_BASE.arg( QString::number( m_currentAlbumId ), "mp32" ) );
-    currentAlbum.setOggTorrentUrl( TORRENTURL_BASE.arg( QString::number( m_currentAlbumId ), "ogg3" ) );
-    m_albumArtistMap.insert( currentAlbum.id(), currentAlbum.artistId() );
-
-    int newId = m_dbHandler->insertAlbum( &currentAlbum );
-    countTransaction();
-
-    //debug() << "inserting genre with album_id = " << newId << " and name = " << genreName;
-    ServiceGenre currentGenre( genre );
-    currentGenre.setAlbumId( newId );
-    m_dbHandler->insertGenre( &currentGenre );
-    countTransaction();
+    //We really do not like albums with no genres, makes the service freeze, so simply ignore this.
+    if( !genre.isEmpty() && genre != "Unknown" )
+    {
+        m_nNumberOfAlbums++;
+        JamendoAlbum currentAlbum( name );
+        currentAlbum.setGenre( genre );
+        currentAlbum.setDescription( description );
+        currentAlbum.setId( m_currentAlbumId );
+        currentAlbum.setArtistId( m_currentArtistId );
+        currentAlbum.setLaunchYear( releaseDate.left( 4 ).toInt() );
+        currentAlbum.setCoverUrl( COVERURL_BASE.arg( m_currentAlbumId ) );
+        currentAlbum.setMp3TorrentUrl( TORRENTURL_BASE.arg( QString::number( m_currentAlbumId ), "mp32" ) );
+        currentAlbum.setOggTorrentUrl( TORRENTURL_BASE.arg( QString::number( m_currentAlbumId ), "ogg3" ) );
+        m_albumArtistMap.insert( currentAlbum.id(), currentAlbum.artistId() );
+
+        int newId = m_dbHandler->insertAlbum( &currentAlbum );
+        countTransaction();
+
+        //debug() << "inserting genre with album_id = " << newId << " and name = " << genreName;
+        ServiceGenre currentGenre( genre );
+        currentGenre.setAlbumId( newId );
+        m_dbHandler->insertGenre( &currentGenre );
+        countTransaction();
+    }
 }
 
 void