Bug 138501

Summary: current SVN, too slow quick search
Product: [Applications] amarok Reporter: Andrew Gaydenko <a>
Component: generalAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: normal CC: stanley_87
Priority: NOR    
Version: 1.4-SVN   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: speed improvement

Description Andrew Gaydenko 2006-12-07 15:48:26 UTC
Version:           current SVN (using KDE KDE 3.5.5)
Installed from:    Gentoo Packages
OS:                Linux

Apparently after last changes in collection db, 'quick search' (filter above collection tree) become very slow, practically unusable for, say, ~200 albums collection.

___________
With SQLite, the search in the collection browser was case-sensitive 
with UTF-8. Patch by Stanislav Nikolov <stanley_87@mail.ru>. (BR 138482)
Comment 1 Mark Kretschmann 2006-12-07 16:11:08 UTC
Stanislav, any ideas on this one?
Comment 2 Stanislav Nikolov 2006-12-07 17:35:22 UTC
Created attachment 18832 [details]
speed improvement

Yes, I guess the previos itreration of the patch was a bit slowish. I think
this brings it in much better form. Please test.
Comment 3 Mark Kretschmann 2006-12-07 17:47:06 UTC
SVN commit 611322 by markey:

Possible fix for collection search performance issue.

BUG: 138501


 M  +11 -12    collectiondb.cpp  


--- trunk/extragear/multimedia/amarok/src/collectiondb.cpp #611321:611322
@@ -8,6 +8,7 @@
 // (c) 2006 Jonas Hurrelmann <j@outpo.st>
 // (c) 2006 Shane King <kde@dontletsstart.com>
 // (c) 2006 Peter C. Ndikuwera <pndiku@gmail.com>
+// (c) 2006 Stanislav Nikolov <valsinats@gmail.com>
 // See COPYING file for licensing information.
 
 #define DEBUG_PREFIX "CollectionDB"
@@ -6200,20 +6201,18 @@
     QString pattern = QString::fromUtf8( (const char*)zA );
     QString text = QString::fromUtf8( (const char*)zB );
 
-    pattern = QRegExp::escape( pattern );
+    int begin = pattern.startsWith( "%" ), end = pattern.endsWith( "%" );
+    pattern = pattern.mid( 1, pattern.length() - 2 );
+    if( argc == 3 ) // The function is given an escape character. In likeCondition() it defaults to '/'
+        pattern.replace( "/%", "%" ).replace( "/_", "_" ).replace( "//", "/" );
 
-    if ( pattern.startsWith("%") ) pattern = ".*" + pattern.mid(1);
-    if ( pattern.endsWith("%") ) pattern = pattern.left( pattern.length() - 1 ) + ".*";
+    int result = 0;
+    if ( begin && end ) result = ( text.find( pattern, 0, 0 ) != -1);
+    else if ( begin ) result = text.startsWith( pattern, 0 );
+    else if ( end ) result = text.endsWith( pattern, 0 );
+    else result = ( text.lower() == pattern.lower() );
 
-    if( argc == 3 ) {
-        const unsigned char *zEsc = sqlite3_value_text( argv[2] );
-        QChar escape = QString::fromUtf8( (const char*)zEsc ).at( 0 );
-        pattern.replace( escape + '%', "%" ).replace( escape + '_', "_" ).replace( escape + '/', "/" );
-    }
-
-    const QRegExp rx( pattern, 0 /* case-sensitive */, 0 /* simple wildcards */ );
-
-    sqlite3_result_int( context, rx.search( text ) != -1 );
+    sqlite3_result_int( context, result );
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
Comment 4 Andrew Gaydenko 2006-12-08 10:42:07 UTC
The fix works for me. Thanks!