From 97a40bb7f35a8323dd99712bf014387add283177 Mon Sep 17 00:00:00 2001 From: eilers Date: Sun, 05 Sep 2004 15:46:47 +0000 Subject: Fixing really stupid caching bug.. Thanks to zecke who found it.. Removed cachefind in backend which isn't needed anymore and not a goot idea... --- (limited to 'libopie2/opiepim') diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index abfd944..221e977 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp @@ -842,6 +842,7 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned // by using the cache.. QArray cachelist = uidlist; + OPimContact retContact; odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; @@ -865,6 +866,8 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons contact.setExtraMap( requestCustom( contact.uid() ) ); odebug << "Caching uid: " << contact.uid() << oendl; cache( contact ); + if ( contact.uid() == uid ) + retContact = contact; resItem = res_noncustom.next(); } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! t3needed = t3.elapsed(); @@ -874,7 +877,7 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed << " ms, mapping: " << t3needed << " ms" << oendl; - return cacheFind( uid ); + return retContact; } QMap OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h index 4f81735..28d9746 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h @@ -72,8 +72,8 @@ class OPimContactAccessBackend_SQL : public OPimContactAccessBackend { QArray allRecords() const; - OPimContact find ( int uid ) const; - OPimContact find( int uid, const QArray&, uint cur, Frontend::CacheDirection ) const; + OPimContact find( int uid ) const; + OPimContact find( int uid, const QArray& items, uint cur, Frontend::CacheDirection ) const; QArray queryByExample ( const OPimContact &query, int settings, const QDateTime& d ); diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h index 15a7b7f..26af762 100644 --- a/libopie2/opiepim/backend/opimaccessbackend.h +++ b/libopie2/opiepim/backend/opimaccessbackend.h @@ -93,9 +93,9 @@ public: * find the OPimRecord with uid @param uid * returns T and T.isEmpty() if nothing was found */ - virtual T find(int uid )const = 0; + virtual T find( int uid )const = 0; - virtual T find(int uid, const QArray& items, + virtual T find( int uid, const QArray& items, uint current, typename Frontend::CacheDirection ) const; /** * clear the back end @@ -131,13 +131,6 @@ protected: void cache( const T& t )const; - /** - * Returns the element with given uid out of the cache. - * Returns empty element if nothing was found. - * Attention: This just works if we have a frontend which contains the cache ! - */ - T cacheFind( int uid ) const; - /** * use a prime number here! */ @@ -173,15 +166,6 @@ void OPimAccessBackend::cache( const T& t )const { m_front->cache( t ); } -template -T OPimAccessBackend::cacheFind( int uid )const { - if ( ! m_front ){ - qWarning ( "No frontend assigned ! Therefore we cannot access the cache to return the right element!" ); - return T(); - } - - return m_front->cacheFind( uid ); -} template void OPimAccessBackend::setSaneCacheSize( int size) { @@ -191,7 +175,7 @@ void OPimAccessBackend::setSaneCacheSize( int size) { template T OPimAccessBackend::find( int uid, const QArray&, uint, typename Frontend::CacheDirection ) const{ - qDebug( "*** Lookahead feature not supported. Fallback to default find!" ); + qDebug( "*** Lookahead feature not supported. Fallback to default find!!" ); return find( uid ); } template diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 12a8bea..4e3e47b 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp @@ -454,7 +454,7 @@ QArray OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, con } OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); - return todo( m_driver->query(&query) ); + return parseResultAndCache( uid, m_driver->query(&query) ); } @@ -492,8 +492,7 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray& ints, if ( res.state() != OSQLResult::Success ) return to; - todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) - return cacheFind( uid ); + return parseResultAndCache( uid, res ); } void OPimTodoAccessBackendSQL::clear() { @@ -630,12 +629,14 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ return true; } } -OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ +OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ if ( res.state() == OSQLResult::Failure ) { OPimTodo to; return to; } + OPimTodo retTodo; + OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); odebug << "todo1" << oendl; @@ -645,9 +646,12 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ for ( ; it != list.end(); ++it ) { odebug << "caching" << oendl; - cache( todo( (*it) ) ); + OPimTodo newTodo = todo( (*it) ); + cache( newTodo ); + if ( newTodo.uid() == uid ) + retTodo = newTodo; } - return to; + return retTodo; } OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { odebug << "todo(ResultItem)" << oendl; @@ -707,9 +711,11 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { return to; } + +// FIXME: Where is the difference to "find" ? (eilers) OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { FindQuery find( uid ); - return todo( m_driver->query(&find) ); + return parseResultAndCache( uid, m_driver->query(&find) ); } /* * update the dict diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 0cc7722..415f791 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h @@ -75,7 +75,7 @@ private: void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; - inline OPimTodo todo( const Opie::DB::OSQLResult& )const; + inline OPimTodo parseResultAndCache( int uid, const Opie::DB::OSQLResult& )const; inline OPimTodo todo( Opie::DB::OSQLResultItem& )const; inline QArray uids( const Opie::DB::OSQLResult& )const; OPimTodo todo( int uid )const; diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 6f01b46..7ab1ea5 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -119,12 +119,12 @@ public: /** * find the OPimRecord uid */ - virtual T find( int uid )const; + T find( int uid )const; /** * read ahead cache find method ;) */ - virtual T find( int uid, const QArray&, + T find( int uid, const QArray&, uint current, typename OTemplateBase::CacheDirection dir = OTemplateBase::Forward )const; -- cgit v0.9.0.2