author | eilers <eilers> | 2004-09-05 15:46:47 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-09-05 15:46:47 (UTC) |
commit | 97a40bb7f35a8323dd99712bf014387add283177 (patch) (unidiff) | |
tree | ec50fbb430f00c86af6ca5bd7c6b94fa29cfe3b1 /libopie2/opiepim/backend | |
parent | f8b02e2ae752ce98b8840735260c4e9b0ff25cb8 (diff) | |
download | opie-97a40bb7f35a8323dd99712bf014387add283177.zip opie-97a40bb7f35a8323dd99712bf014387add283177.tar.gz opie-97a40bb7f35a8323dd99712bf014387add283177.tar.bz2 |
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...
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/opimaccessbackend.h | 22 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 20 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 2 |
5 files changed, 23 insertions, 30 deletions
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 | |||
842 | // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned | 842 | // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned |
843 | // by using the cache.. | 843 | // by using the cache.. |
844 | QArray<int> cachelist = uidlist; | 844 | QArray<int> cachelist = uidlist; |
845 | OPimContact retContact; | ||
845 | 846 | ||
846 | odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; | 847 | odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; |
847 | 848 | ||
@@ -865,6 +866,8 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons | |||
865 | contact.setExtraMap( requestCustom( contact.uid() ) ); | 866 | contact.setExtraMap( requestCustom( contact.uid() ) ); |
866 | odebug << "Caching uid: " << contact.uid() << oendl; | 867 | odebug << "Caching uid: " << contact.uid() << oendl; |
867 | cache( contact ); | 868 | cache( contact ); |
869 | if ( contact.uid() == uid ) | ||
870 | retContact = contact; | ||
868 | resItem = res_noncustom.next(); | 871 | resItem = res_noncustom.next(); |
869 | } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! | 872 | } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! |
870 | t3needed = t3.elapsed(); | 873 | t3needed = t3.elapsed(); |
@@ -874,7 +877,7 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons | |||
874 | odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed | 877 | odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed |
875 | << " ms, mapping: " << t3needed << " ms" << oendl; | 878 | << " ms, mapping: " << t3needed << " ms" << oendl; |
876 | 879 | ||
877 | return cacheFind( uid ); | 880 | return retContact; |
878 | } | 881 | } |
879 | 882 | ||
880 | QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const | 883 | QMap<int, QString> 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 { | |||
72 | 72 | ||
73 | QArray<int> allRecords() const; | 73 | QArray<int> allRecords() const; |
74 | 74 | ||
75 | OPimContact find ( int uid ) const; | 75 | OPimContact find( int uid ) const; |
76 | OPimContact find( int uid, const QArray<int>&, uint cur, Frontend::CacheDirection ) const; | 76 | OPimContact find( int uid, const QArray<int>& items, uint cur, Frontend::CacheDirection ) const; |
77 | 77 | ||
78 | QArray<int> queryByExample ( const OPimContact &query, int settings, | 78 | QArray<int> queryByExample ( const OPimContact &query, int settings, |
79 | const QDateTime& d ); | 79 | 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: | |||
93 | * find the OPimRecord with uid @param uid | 93 | * find the OPimRecord with uid @param uid |
94 | * returns T and T.isEmpty() if nothing was found | 94 | * returns T and T.isEmpty() if nothing was found |
95 | */ | 95 | */ |
96 | virtual T find(int uid )const = 0; | 96 | virtual T find( int uid )const = 0; |
97 | 97 | ||
98 | virtual T find(int uid, const QArray<int>& items, | 98 | virtual T find( int uid, const QArray<int>& items, |
99 | uint current, typename Frontend::CacheDirection ) const; | 99 | uint current, typename Frontend::CacheDirection ) const; |
100 | /** | 100 | /** |
101 | * clear the back end | 101 | * clear the back end |
@@ -131,13 +131,6 @@ protected: | |||
131 | 131 | ||
132 | void cache( const T& t )const; | 132 | void cache( const T& t )const; |
133 | 133 | ||
134 | /** | ||
135 | * Returns the element with given uid out of the cache. | ||
136 | * Returns empty element if nothing was found. | ||
137 | * <b>Attention:</b> This just works if we have a frontend which contains the cache ! | ||
138 | */ | ||
139 | T cacheFind( int uid ) const; | ||
140 | |||
141 | /** | 134 | /** |
142 | * use a prime number here! | 135 | * use a prime number here! |
143 | */ | 136 | */ |
@@ -173,15 +166,6 @@ void OPimAccessBackend<T>::cache( const T& t )const { | |||
173 | m_front->cache( t ); | 166 | m_front->cache( t ); |
174 | } | 167 | } |
175 | 168 | ||
176 | template <class T> | ||
177 | T OPimAccessBackend<T>::cacheFind( int uid )const { | ||
178 | if ( ! m_front ){ | ||
179 | qWarning ( "No frontend assigned ! Therefore we cannot access the cache to return the right element!" ); | ||
180 | return T(); | ||
181 | } | ||
182 | |||
183 | return m_front->cacheFind( uid ); | ||
184 | } | ||
185 | 169 | ||
186 | template <class T> | 170 | template <class T> |
187 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 171 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
@@ -191,7 +175,7 @@ void OPimAccessBackend<T>::setSaneCacheSize( int size) { | |||
191 | template <class T> | 175 | template <class T> |
192 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 176 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
193 | uint, typename Frontend::CacheDirection ) const{ | 177 | uint, typename Frontend::CacheDirection ) const{ |
194 | qDebug( "*** Lookahead feature not supported. Fallback to default find!" ); | 178 | qDebug( "*** Lookahead feature not supported. Fallback to default find!!" ); |
195 | return find( uid ); | 179 | return find( uid ); |
196 | } | 180 | } |
197 | template <class T> | 181 | template <class T> |
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<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, con | |||
454 | } | 454 | } |
455 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | 455 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ |
456 | FindQuery query( uid ); | 456 | FindQuery query( uid ); |
457 | return todo( m_driver->query(&query) ); | 457 | return parseResultAndCache( uid, m_driver->query(&query) ); |
458 | 458 | ||
459 | } | 459 | } |
460 | 460 | ||
@@ -492,8 +492,7 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
492 | if ( res.state() != OSQLResult::Success ) | 492 | if ( res.state() != OSQLResult::Success ) |
493 | return to; | 493 | return to; |
494 | 494 | ||
495 | todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) | 495 | return parseResultAndCache( uid, res ); |
496 | return cacheFind( uid ); | ||
497 | } | 496 | } |
498 | 497 | ||
499 | void OPimTodoAccessBackendSQL::clear() { | 498 | void OPimTodoAccessBackendSQL::clear() { |
@@ -630,12 +629,14 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | |||
630 | return true; | 629 | return true; |
631 | } | 630 | } |
632 | } | 631 | } |
633 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | 632 | OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ |
634 | if ( res.state() == OSQLResult::Failure ) { | 633 | if ( res.state() == OSQLResult::Failure ) { |
635 | OPimTodo to; | 634 | OPimTodo to; |
636 | return to; | 635 | return to; |
637 | } | 636 | } |
638 | 637 | ||
638 | OPimTodo retTodo; | ||
639 | |||
639 | OSQLResultItem::ValueList list = res.results(); | 640 | OSQLResultItem::ValueList list = res.results(); |
640 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 641 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
641 | odebug << "todo1" << oendl; | 642 | odebug << "todo1" << oendl; |
@@ -645,9 +646,12 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | |||
645 | 646 | ||
646 | for ( ; it != list.end(); ++it ) { | 647 | for ( ; it != list.end(); ++it ) { |
647 | odebug << "caching" << oendl; | 648 | odebug << "caching" << oendl; |
648 | cache( todo( (*it) ) ); | 649 | OPimTodo newTodo = todo( (*it) ); |
650 | cache( newTodo ); | ||
651 | if ( newTodo.uid() == uid ) | ||
652 | retTodo = newTodo; | ||
649 | } | 653 | } |
650 | return to; | 654 | return retTodo; |
651 | } | 655 | } |
652 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 656 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
653 | odebug << "todo(ResultItem)" << oendl; | 657 | odebug << "todo(ResultItem)" << oendl; |
@@ -707,9 +711,11 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
707 | 711 | ||
708 | return to; | 712 | return to; |
709 | } | 713 | } |
714 | |||
715 | // FIXME: Where is the difference to "find" ? (eilers) | ||
710 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { | 716 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { |
711 | FindQuery find( uid ); | 717 | FindQuery find( uid ); |
712 | return todo( m_driver->query(&find) ); | 718 | return parseResultAndCache( uid, m_driver->query(&find) ); |
713 | } | 719 | } |
714 | /* | 720 | /* |
715 | * update the dict | 721 | * 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: | |||
75 | void update()const; | 75 | void update()const; |
76 | void fillDict(); | 76 | void fillDict(); |
77 | inline bool date( QDate& date, const QString& )const; | 77 | inline bool date( QDate& date, const QString& )const; |
78 | inline OPimTodo todo( const Opie::DB::OSQLResult& )const; | 78 | inline OPimTodo parseResultAndCache( int uid, const Opie::DB::OSQLResult& )const; |
79 | inline OPimTodo todo( Opie::DB::OSQLResultItem& )const; | 79 | inline OPimTodo todo( Opie::DB::OSQLResultItem& )const; |
80 | inline QArray<int> uids( const Opie::DB::OSQLResult& )const; | 80 | inline QArray<int> uids( const Opie::DB::OSQLResult& )const; |
81 | OPimTodo todo( int uid )const; | 81 | OPimTodo todo( int uid )const; |