author | zecke <zecke> | 2002-10-10 20:16:15 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-10 20:16:15 (UTC) |
commit | 48b06312289a90ad38278d3adb0bce5e9e0bd67e (patch) (side-by-side diff) | |
tree | e5123b76d501eeb669ac6b43b8da746eae36e638 /libopie/pim/otodoaccesssql.cpp | |
parent | c90676c42c7be606a9fc690278b67909ba6a9c99 (diff) | |
download | opie-48b06312289a90ad38278d3adb0bce5e9e0bd67e.zip opie-48b06312289a90ad38278d3adb0bce5e9e0bd67e.tar.gz opie-48b06312289a90ad38278d3adb0bce5e9e0bd67e.tar.bz2 |
Implement read ahead on the XML resource...
Scrolling is now noticeable faster with 10.000 items
but not as fast the XML backend...
OPimCache can be tuned and Query->OTodo too
Diffstat (limited to 'libopie/pim/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 8add9f7..a059dab 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -76,19 +76,23 @@ namespace { }; /** * a find query */ class FindQuery : public OSQLQuery { public: FindQuery(int uid); + FindQuery(const QArray<int>& ); ~FindQuery(); QString query()const; private: + QString single()const; + QString multi()const; + QArray<int> m_uids; int m_uid; }; /** * overdue query */ class OverDueQuery : public OSQLQuery { public: @@ -133,16 +137,17 @@ namespace { } InsertQuery::~InsertQuery() { } /* * converts from a OTodo to a query * we leave out X-Ref + Alarms */ QString InsertQuery::query()const{ + int year, month, day; year = month = day = 0; if (m_todo.hasDueDate() ) { QDate date = m_todo.dueDate(); year = date.year(); month = date.month(); day = date.day(); } @@ -170,23 +175,41 @@ namespace { ClearQuery::~ClearQuery() {} QString ClearQuery::query()const { QString qu = "drop table todolist"; return qu; } FindQuery::FindQuery(int uid) : OSQLQuery(), m_uid(uid ) { } + FindQuery::FindQuery(const QArray<int>& ints) + : OSQLQuery(), m_uids(ints){ + } FindQuery::~FindQuery() { } QString FindQuery::query()const{ + if (m_uids.count() == 0 ) + return single(); + else + return multi(); + } + QString FindQuery::single()const{ QString qu = "select uid, categories, completed, progress, summary, "; qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); return qu; } + QString FindQuery::multi()const { + QString qu = "select uid, categories, completed, progress, summary, "; + qu += "DueDate, priority, description from todolist where "; + for (uint i = 0; i < m_uids.count(); i++ ) { + qu += " UID = " + QString::number( m_uids[i] ) + " OR"; + } + qu.remove( qu.length()-2, 2 ); + return qu; + } OverDueQuery::OverDueQuery(): OSQLQuery() {} OverDueQuery::~OverDueQuery() {} QString OverDueQuery::query()const { QDate date = QDate::currentDate(); QString str; str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); @@ -256,16 +279,49 @@ QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ QArray<int> ints(0); return ints; } OTodo OTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); return todo( m_driver->query(&query) ); } +OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, + uint cur, Frontend::CacheDirection dir ) const{ + qWarning("searching for %d", uid ); + QArray<int> search( 8 ); + uint size =0; + OTodo to; + + // we try to cache 8 items + switch( dir ) { + /* forward */ + case 0: + for (uint i = cur; i < ints.count() && size < 8; i++ ) { + qWarning("size %d %d", size, ints[i] ); + search[size] = ints[i]; + size++; + } + break; + /* reverse */ + case 1: + for (uint i = cur; i >= 0 && size < 8; i-- ) { + search[size] = ints[i]; + size++; + } + break; + } + search.resize( size ); + FindQuery query( search ); + OSQLResult res = m_driver->query( &query ); + if ( res.state() != OSQLResult::Success ) + return to; + + return todo( res ); +} void OTodoAccessBackendSQL::clear() { ClearQuery cle; OSQLResult res = m_driver->query( &cle ); CreateQuery qu; res = m_driver->query(&qu); } bool OTodoAccessBackendSQL::add( const OTodo& t) { InsertQuery ins( t ); @@ -388,24 +444,37 @@ bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ if ( res.state() == OSQLResult::Failure ) { OTodo to; return to; } OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); - + qWarning("todo1"); + OTodo to = todo( (*it) ); + cache( to ); + ++it; + + for ( ; it != list.end(); ++it ) { + qWarning("caching"); + cache( todo( (*it) ) ); + } + return to; +} +OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { + qWarning("todo"); bool has = false; QDate da = QDate::currentDate(); - has = date( da, (*it).data("DueDate") ); - QStringList cats = QStringList::split(";", (*it).data("categories") ); + has = date( da, item.data("DueDate") ); + QStringList cats = QStringList::split(";", item.data("categories") ); - OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), - cats, (*it).data("summary"), (*it).data("description"), - (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); + OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), + cats, item.data("summary"), item.data("description"), + item.data("progress").toUShort(), has, da, + item.data("uid").toInt() ); return to; } OTodo OTodoAccessBackendSQL::todo( int uid )const { FindQuery find( uid ); return todo( m_driver->query(&find) ); } /* * update the dict |