author | zecke <zecke> | 2002-10-13 02:22:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-13 02:22:58 (UTC) |
commit | d96ce086c617b5b2efc5081cd10a43257a78f488 (patch) (side-by-side diff) | |
tree | 4f6b80b7295127bd82cc5fb8ffd1d532c42a396b | |
parent | 2ce86d9be1bbf99092348adf815578b110fe7289 (diff) | |
download | opie-d96ce086c617b5b2efc5081cd10a43257a78f488.zip opie-d96ce086c617b5b2efc5081cd10a43257a78f488.tar.gz opie-d96ce086c617b5b2efc5081cd10a43257a78f488.tar.bz2 |
OPimAccessBackend nothing tried a isDirty()const ... but removed it
ORecordList uidAt(uint index ) added
Speed Improvements at the SQL backend
do not load the list of uids until it's really needed
do not reload the uid list until it's really needed
we got a bitfield m_dirty there...
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 5 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 5 |
8 files changed, 58 insertions, 24 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h @@ -183,14 +183,12 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, * avoid two finds in QCache... */ // qWarning("find it now %d", uid ); if (m_cache.contains( uid ) ) { - qWarning("m cache contains %d", uid); return m_cache.find( uid ); } T t = m_backEnd->find( uid, ar, current, dir ); - qWarning("found it and cache it now %d", uid); cache( t ); return t; } template <class T> diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -108,8 +108,9 @@ public: */ uint count()const; T operator[]( uint i ); + int uidAt(uint i ); // FIXME implemenent remove /* ConstIterator begin()const; ConstIterator end()const; @@ -261,5 +262,9 @@ template <class T> T ORecordList<T>::operator[]( uint i ) { /* forward */ return m_acc->find( m_ids[i], m_ids, i ); } +template <class T> +int ORecordList<T>::uidAt( uint i ) { + return m_ids[i]; +} #endif diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -240,9 +240,9 @@ namespace { } }; OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) - : OTodoAccessBackend(), m_dict(15) + : OTodoAccessBackend(), m_dict(15), m_dirty(true) { QString fi = file; if ( fi.isEmpty() ) fi = Global::applicationFileName( "todolist", "todolist.db" ); @@ -260,10 +260,9 @@ bool OTodoAccessBackendSQL::load(){ CreateQuery creat; OSQLResult res = m_driver->query(&creat ); - update(); - qWarning("loaded %d", m_uids.count() ); + m_dirty = true; return true; } bool OTodoAccessBackendSQL::reload(){ return load(); @@ -272,8 +271,11 @@ bool OTodoAccessBackendSQL::reload(){ bool OTodoAccessBackendSQL::save(){ return m_driver->close(); } QArray<int> OTodoAccessBackendSQL::allRecords()const { + if (m_dirty ) + update(); + return m_uids; } QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ QArray<int> ints(0); @@ -302,9 +304,9 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, } break; /* reverse */ case 1: - for (uint i = cur; i >= 0 && size < 8; i-- ) { + for (uint i = cur; i != 0 && size < 8; i-- ) { search[size] = ints[i]; size++; } break; @@ -341,9 +343,9 @@ bool OTodoAccessBackendSQL::remove( int uid ) { if ( res.state() == OSQLResult::Failure ) return false; - update(); + m_dirty = true; return true; } /* * FIXME better set query @@ -351,9 +353,11 @@ bool OTodoAccessBackendSQL::remove( int uid ) { * now we remove */ bool OTodoAccessBackendSQL::replace( const OTodo& t) { remove( t.uid() ); - return add(t); + bool b= add(t); + m_dirty = false; // we changed some stuff but the UID stayed the same + return b; } QArray<int> OTodoAccessBackendSQL::overDue() { OverDueQuery qu; return uids( m_driver->query(&qu ) ); @@ -368,8 +372,9 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, * */ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { + qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; /* @@ -420,10 +425,13 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, case 3: query += "DueDate"; break; } - if ( !asc ) + + if ( !asc ) { + qWarning("not ascending!"); query += " DESC"; + } qWarning( query ); OSQLRawQuery raw(query ); return uids( m_driver->query(&raw) ); @@ -500,15 +508,20 @@ void OTodoAccessBackendSQL::fillDict() { m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); } -void OTodoAccessBackendSQL::update() { +/* + * need to be const so let's fool the + * compiler :( + */ +void OTodoAccessBackendSQL::update()const { + ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); if ( res.state() != OSQLResult::Success ) return; - m_uids = uids( res ); + ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h @@ -31,9 +31,9 @@ public: const QDate& end, bool includeNoDates ); QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); private: - void update(); + void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; inline OTodo todo( OSQLResultItem& )const; @@ -42,8 +42,9 @@ private: QAsciiDict<int> m_dict; OSQLDriver* m_driver; QArray<int> m_uids; + bool m_dirty : 1; }; #endif diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp @@ -240,9 +240,9 @@ namespace { } }; OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) - : OTodoAccessBackend(), m_dict(15) + : OTodoAccessBackend(), m_dict(15), m_dirty(true) { QString fi = file; if ( fi.isEmpty() ) fi = Global::applicationFileName( "todolist", "todolist.db" ); @@ -260,10 +260,9 @@ bool OTodoAccessBackendSQL::load(){ CreateQuery creat; OSQLResult res = m_driver->query(&creat ); - update(); - qWarning("loaded %d", m_uids.count() ); + m_dirty = true; return true; } bool OTodoAccessBackendSQL::reload(){ return load(); @@ -272,8 +271,11 @@ bool OTodoAccessBackendSQL::reload(){ bool OTodoAccessBackendSQL::save(){ return m_driver->close(); } QArray<int> OTodoAccessBackendSQL::allRecords()const { + if (m_dirty ) + update(); + return m_uids; } QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ QArray<int> ints(0); @@ -302,9 +304,9 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, } break; /* reverse */ case 1: - for (uint i = cur; i >= 0 && size < 8; i-- ) { + for (uint i = cur; i != 0 && size < 8; i-- ) { search[size] = ints[i]; size++; } break; @@ -341,9 +343,9 @@ bool OTodoAccessBackendSQL::remove( int uid ) { if ( res.state() == OSQLResult::Failure ) return false; - update(); + m_dirty = true; return true; } /* * FIXME better set query @@ -351,9 +353,11 @@ bool OTodoAccessBackendSQL::remove( int uid ) { * now we remove */ bool OTodoAccessBackendSQL::replace( const OTodo& t) { remove( t.uid() ); - return add(t); + bool b= add(t); + m_dirty = false; // we changed some stuff but the UID stayed the same + return b; } QArray<int> OTodoAccessBackendSQL::overDue() { OverDueQuery qu; return uids( m_driver->query(&qu ) ); @@ -368,8 +372,9 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, * */ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { + qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; /* @@ -420,10 +425,13 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, case 3: query += "DueDate"; break; } - if ( !asc ) + + if ( !asc ) { + qWarning("not ascending!"); query += " DESC"; + } qWarning( query ); OSQLRawQuery raw(query ); return uids( m_driver->query(&raw) ); @@ -500,15 +508,20 @@ void OTodoAccessBackendSQL::fillDict() { m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); } -void OTodoAccessBackendSQL::update() { +/* + * need to be const so let's fool the + * compiler :( + */ +void OTodoAccessBackendSQL::update()const { + ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); if ( res.state() != OSQLResult::Success ) return; - m_uids = uids( res ); + ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h @@ -31,9 +31,9 @@ public: const QDate& end, bool includeNoDates ); QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); private: - void update(); + void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; inline OTodo todo( OSQLResultItem& )const; @@ -42,8 +42,9 @@ private: QAsciiDict<int> m_dict; OSQLDriver* m_driver; QArray<int> m_uids; + bool m_dirty : 1; }; #endif diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -183,14 +183,12 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, * avoid two finds in QCache... */ // qWarning("find it now %d", uid ); if (m_cache.contains( uid ) ) { - qWarning("m cache contains %d", uid); return m_cache.find( uid ); } T t = m_backEnd->find( uid, ar, current, dir ); - qWarning("found it and cache it now %d", uid); cache( t ); return t; } template <class T> diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h @@ -108,8 +108,9 @@ public: */ uint count()const; T operator[]( uint i ); + int uidAt(uint i ); // FIXME implemenent remove /* ConstIterator begin()const; ConstIterator end()const; @@ -261,5 +262,9 @@ template <class T> T ORecordList<T>::operator[]( uint i ) { /* forward */ return m_acc->find( m_ids[i], m_ids, i ); } +template <class T> +int ORecordList<T>::uidAt( uint i ) { + return m_ids[i]; +} #endif |