[patch] Sorting in TodoAccess SQL backend

Marcin Juszkiewicz <[email protected]>
Newsgroups gmane.comp.handhelds.opie.devel
Organization OpenEmbedded
Message-ID <[email protected]>
I use SQLite backend for PIM on my Zaurus. Yesterday I checked how much 
time does Today use for starting and for 1 birthday, 1 event and 3 todos 
it was ~10s. Most of time was spent in TodoAccess sorted() method. As I 
prefer giving all that kind of actions to database I looked into code and 
re-added sorted() method for SQL backend. Result is in attachment (I don't 
want to push it before review).

With that patch it is much faster.

-- 
JID: hrw-jabber.org
Sharp Zaurus C-760 (OZ 3.5.x)
OpenEmbedded/OpenZaurus/OPIE developer

             Computer, n.:
             	A device designed to speed and automate errors.

_______________________________________________

http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex

Opie-devel mailing list
[email protected]
https://handhelds.org/mailman/listinfo/opie-devel
libopie-todoaccess-sql-sorted.diff (text/x-diff, 3.6 KB)
Index: backend/otodoaccesssql.cpp
===================================================================
RCS file: /cvs/opie/libopie2/opiepim/backend/otodoaccesssql.cpp,v
retrieving revision 1.26
diff -u -u -r1.26 otodoaccesssql.cpp
--- libopie2/opiepim/backend/otodoaccesssql.cpp	28 Dec 2004 14:19:26 -0000	1.26
+++ libopie2/opiepim/backend/otodoaccesssql.cpp	2 Dec 2005 15:35:44 -0000
@@ -34,6 +34,7 @@
 #include <opie2/osqlmanager.h>
 #include <opie2/osqlquery.h>
 
+#include <opie2/otodoaccess.h>
 #include <opie2/otodoaccesssql.h>
 #include <opie2/opimstate.h>
 #include <opie2/opimnotifymanager.h>
@@ -553,12 +554,12 @@
     return uids (m_driver->query(&ef) );
 }
 
-#if 0
+#if 1
 /*
  *
  */
-QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
-                                           int sortFilter, int cat ) {
+UIDArray OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
+                                           int sortFilter, const QArray<int>& categories ) const{
     odebug << "sorted " << asc << ", " << sortOrder << "" << oendl;
     QString query;
     query = "select uid from todolist WHERE ";
@@ -570,17 +571,17 @@
      *
      */
     /* Category */
-    if ( sortFilter & OPimTodoAccess::FilterCategory ) {
-        QString str;
-        if (cat != 0 ) str = QString::number( cat );
-        query += " categories like '%" +str+"%' AND";
-    }
+//    if ( sortFilter & OPimTodoAccess::FilterCategory ) {
+//        QString str;
+//        if (cat != 0 ) str = QString::number( cat );
+//        query += " categories like '%" +str+"%' AND";
+//    }
     /* Show only overdue */
     if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
         QDate date = QDate::currentDate();
         QString due;
         QString base;
-        base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
+        base = QString("DueDate != '0000-00-00' AND DueDate <= '%1-%2-%3' AND completed = 0")
         .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
         .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
         .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
@@ -589,9 +590,10 @@
     /* not show completed */
     if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
         query += " completed = 0 AND";
-    }else{
-       query += " ( completed = 1 OR  completed = 0) AND";
-    }
+	}
+//    else{
+//       query += " ( completed = 1 OR  completed = 0) AND";
+//    }
     /* strip the end */
     query = query.remove( query.length()-3, 3 );
 
@@ -603,15 +605,16 @@
     query += "ORDER BY ";
     switch( sortOrder ) {
         /* completed */
+	default:
     case OPimTodoAccess::Completed:
         query += "completed";
         break;
     case OPimTodoAccess::Priority:
         query += "priority";
         break;
-    case OPimTodoAccess::SortSummary:
-        query += "summary";
-        break;
+//    case OPimTodoAccess::SortSummary:
+//        query += "summary";
+//        break;
     case OPimTodoAccess::Deadline:
         query += "DueDate";
         break;
Index: backend/otodoaccesssql.h
===================================================================
RCS file: /cvs/opie/libopie2/opiepim/backend/otodoaccesssql.h,v
retrieving revision 1.14
diff -u -u -r1.14 otodoaccesssql.h
--- libopie2/opiepim/backend/otodoaccesssql.h	28 Dec 2004 14:19:26 -0000	1.14
+++ libopie2/opiepim/backend/otodoaccesssql.h	2 Dec 2005 15:35:44 -0000
@@ -67,6 +67,7 @@
     QArray<UID> matchRegexp(  const QRegExp &r ) const;
     void removeAllCompleted();
 
+    UIDArray sorted( bool, int, int, const QArray<int>& )const;
 
 private:
     void update()const;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.