extragear/multimedia/amarok/src
Mark Kretschmann
markey at web.de
Sun Sep 3 21:38:08 UTC 2006
SVN commit 580555 by markey:
Speed up playlist XML writing approximately 10 times. This patch considerably improves Amarok's overall performance with big playlists and also cuts down on shutdown time.
Details:
Problem was that Playlist::saveXML() would invoke methods like MetaBundle::score(), which accessed the database in many cases. This database access was extremely slow, so we circumvent it and use cached values instead.
Another optimization is that we now write the XML data to a string before writing to the target file.
CCMAIL: amarok at kde.org
M +14 -14 metabundle.cpp
M +6 -5 metabundle.h
M +7 -2 playlist.cpp
--- trunk/extragear/multimedia/amarok/src/metabundle.cpp #580554:580555
@@ -645,32 +645,32 @@
m_filesize = QFile( path ).size();
}
-int MetaBundle::score() const
+int MetaBundle::score( bool ensureCached ) const
{
- if( m_score == Undetermined )
+ if( m_score == Undetermined && !ensureCached )
//const_cast is ugly, but other option was mutable, and then we lose const correctness checking
//everywhere else
*const_cast<int*>(&m_score) = CollectionDB::instance()->getSongPercentage( m_url.path() );
return m_score;
}
-int MetaBundle::rating() const
+int MetaBundle::rating( bool ensureCached ) const
{
- if( m_rating == Undetermined )
+ if( m_rating == Undetermined && !ensureCached )
*const_cast<int*>(&m_rating) = CollectionDB::instance()->getSongRating( m_url.path() );
return m_rating;
}
-int MetaBundle::playCount() const
+int MetaBundle::playCount( bool ensureCached ) const
{
- if( m_playCount == Undetermined )
+ if( m_playCount == Undetermined && !ensureCached )
*const_cast<int*>(&m_playCount) = CollectionDB::instance()->getPlayCount( m_url.path() );
return m_playCount;
}
-uint MetaBundle::lastPlay() const
+uint MetaBundle::lastPlay( bool ensureCached ) const
{
- if( (int)m_lastPlay == abs(Undetermined) )
+ if( (int)m_lastPlay == abs(Undetermined) && !ensureCached )
*const_cast<uint*>(&m_lastPlay) = CollectionDB::instance()->getLastPlay( m_url.path() ).toTime_t();
return m_lastPlay;
}
@@ -754,7 +754,7 @@
}
}
-QString MetaBundle::exactText( int column ) const
+QString MetaBundle::exactText( int column, bool ensureCached ) const
{
switch( column )
{
@@ -774,10 +774,10 @@
case Length: return QString::number( length() );
case Bitrate: return QString::number( bitrate() );
case SampleRate: return QString::number( sampleRate() );
- case Score: return QString::number( score() );
- case Rating: return QString::number( rating() );
- case PlayCount: return QString::number( playCount() );
- case LastPlayed: return QString::number( lastPlay() );
+ case Score: return QString::number( score( ensureCached ) );
+ case Rating: return QString::number( rating( ensureCached ) );
+ case PlayCount: return QString::number( playCount( ensureCached ) );
+ case LastPlayed: return QString::number( lastPlay( ensureCached ) );
case Filesize: return QString::number( filesize() );
case Mood: return QString::null;
default: warning() << "Tried to get the text of a nonexistent column! [" << column << endl;
@@ -1440,7 +1440,7 @@
{
QDomElement tag = QDomSucksItNeedsADocument.createElement( exactColumnName( i ) );
//debug() << "exactColumName(i) = " << exactColumnName( i ) << endl;
- QDomText text = QDomSucksItNeedsADocument.createTextNode( exactText( i ) );
+ QDomText text = QDomSucksItNeedsADocument.createTextNode( exactText( i, true ) );
//debug() << "exactText(i) = " << exactText( i ) << endl;
tag.appendChild( text );
--- trunk/extragear/multimedia/amarok/src/metabundle.h #580554:580555
@@ -183,7 +183,7 @@
/** Returns a string representation of the tag at \p column, in a format suitable for internal purposes.
For example, for a track 3:24 long, it'll return "204" (seconds).
This should not be used for displaying the tag to the user. */
- QString exactText( int column ) const;
+ QString exactText( int column, bool ensureCached = false ) const;
/** Sets the tag at \p column from a string in the same format as returned by exactText(). */
void setExactText( int column, const QString &text );
@@ -238,12 +238,13 @@
int length() const;
int bitrate() const;
int sampleRate() const;
- int score() const;
- int rating() const; //returns rating * 2, to accommodate .5 ratings
- int playCount() const;
+ int score( bool ensureCached = false ) const;
+ int rating( bool ensureCached = false ) const; //returns rating * 2, to accommodate .5 ratings
+ int playCount( bool ensureCached = false ) const;
+ uint lastPlay( bool ensureCached = false ) const;
+
Moodbar &moodbar();
const Moodbar &moodbar_const() const;
- uint lastPlay() const;
int filesize() const;
--- trunk/extragear/multimedia/amarok/src/playlist.cpp #580554:580555
@@ -3130,11 +3130,13 @@
void
Playlist::saveXML( const QString &path )
{
+ DEBUG_BLOCK
+
QFile file( path );
-
if( !file.open( IO_WriteOnly ) ) return;
- QTextStream stream( &file );
+ QString buffer;
+ QTextStream stream( &buffer, IO_WriteOnly );
stream.setEncoding( QTextStream::UnicodeUTF8 );
stream << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
@@ -3165,6 +3167,9 @@
}
stream << "</playlist>\n";
+
+ QTextStream fstream( &file );
+ fstream << buffer;
}
void
More information about the Amarok
mailing list