Commit 689011e6 authored by chriadam's avatar chriadam

[libcontacts] Explicitly tell models to update section bucket index caches. Contributes to JB#45504

When contact data changes in the backend and we have pulled these
changes into the model, we need to tell the attached models that
they need to recalculate their cache of section bucket indexes.

Note that we cannot have a single cache of section bucket indexes
which the models read, as models can have a search filter applied
which means the indexes of contacts in the seaside cache won't
necessarily match what the model expects.
parent f90aceb5
...@@ -999,6 +999,7 @@ bool SeasideCache::saveContact(const QContact &contact) ...@@ -999,6 +999,7 @@ bool SeasideCache::saveContact(const QContact &contact)
} }
instancePtr->requestUpdate(); instancePtr->requestUpdate();
instancePtr->updateSectionBucketIndexCaches();
return true; return true;
} }
...@@ -2034,6 +2035,7 @@ void SeasideCache::dataChanged() ...@@ -2034,6 +2035,7 @@ void SeasideCache::dataChanged()
model->updateGroupProperty(); model->updateGroupProperty();
model->sourceItemsChanged(); model->sourceItemsChanged();
model->sourceDataChanged(0, m_contacts[i].size()); model->sourceDataChanged(0, m_contacts[i].size());
model->updateSectionBucketIndexCache();
} }
} }
...@@ -2342,6 +2344,7 @@ void SeasideCache::contactsAvailable() ...@@ -2342,6 +2344,7 @@ void SeasideCache::contactsAvailable()
if (contacts.count() == 1 || request == &m_fetchByIdRequest) { if (contacts.count() == 1 || request == &m_fetchByIdRequest) {
// Process these results immediately // Process these results immediately
applyContactUpdates(contacts, queryDetailTypes); applyContactUpdates(contacts, queryDetailTypes);
updateSectionBucketIndexCaches(); // note: can cause out-of-order since this doesn't result in refresh request. TODO: remove this line?
} else { } else {
// Add these contacts to the list to be progressively appended // Add these contacts to the list to be progressively appended
QList<QPair<QSet<QContactDetail::DetailType>, QList<QContact> > >::iterator it = m_contactsToUpdate.begin(), end = m_contactsToUpdate.end(); QList<QPair<QSet<QContactDetail::DetailType>, QList<QContact> > >::iterator it = m_contactsToUpdate.begin(), end = m_contactsToUpdate.end();
...@@ -2406,6 +2409,7 @@ void SeasideCache::applyPendingContactUpdates() ...@@ -2406,6 +2409,7 @@ void SeasideCache::applyPendingContactUpdates()
makePopulated(FilterOnline); makePopulated(FilterOnline);
qDebug() << "Online queried in" << m_timer.elapsed() << "ms"; qDebug() << "Online queried in" << m_timer.elapsed() << "ms";
} }
updateSectionBucketIndexCaches();
} }
} else { } else {
QList<QPair<QSet<QContactDetail::DetailType>, QList<QContact> > >::iterator it = m_contactsToUpdate.begin(); QList<QPair<QSet<QContactDetail::DetailType>, QList<QContact> > >::iterator it = m_contactsToUpdate.begin();
...@@ -2419,6 +2423,17 @@ void SeasideCache::applyPendingContactUpdates() ...@@ -2419,6 +2423,17 @@ void SeasideCache::applyPendingContactUpdates()
if (updatedContacts.isEmpty()) { if (updatedContacts.isEmpty()) {
m_contactsToUpdate.erase(it); m_contactsToUpdate.erase(it);
updateSectionBucketIndexCaches();
}
}
}
void SeasideCache::updateSectionBucketIndexCaches()
{
for (int i = 0; i < FilterTypesCount; ++i) {
const QList<ListModel *> &models = m_models[i];
for (ListModel *model : models) {
model->updateSectionBucketIndexCache();
} }
} }
} }
......
...@@ -232,6 +232,8 @@ public: ...@@ -232,6 +232,8 @@ public:
virtual void updateDisplayLabelOrder() = 0; virtual void updateDisplayLabelOrder() = 0;
virtual void updateSortProperty() = 0; virtual void updateSortProperty() = 0;
virtual void updateGroupProperty() = 0; virtual void updateGroupProperty() = 0;
virtual void updateSectionBucketIndexCache() = 0;
}; };
struct ResolveListener struct ResolveListener
...@@ -377,6 +379,7 @@ private: ...@@ -377,6 +379,7 @@ private:
void updateContacts(const QList<QContactId> &contactIds, QList<QContactId> *updateList); void updateContacts(const QList<QContactId> &contactIds, QList<QContactId> *updateList);
void applyPendingContactUpdates(); void applyPendingContactUpdates();
void applyContactUpdates(const QList<QContact> &contacts, const QSet<QContactDetail::DetailType> &queryDetailTypes); void applyContactUpdates(const QList<QContact> &contacts, const QSet<QContactDetail::DetailType> &queryDetailTypes);
void updateSectionBucketIndexCaches();
void resolveUnknownAddresses(const QString &first, const QString &second, CacheItem *item); void resolveUnknownAddresses(const QString &first, const QString &second, CacheItem *item);
bool updateContactIndexing(const QContact &oldContact, const QContact &contact, quint32 iid, const QSet<QContactDetail::DetailType> &queryDetailTypes, CacheItem *item); bool updateContactIndexing(const QContact &oldContact, const QContact &contact, quint32 iid, const QSet<QContactDetail::DetailType> &queryDetailTypes, CacheItem *item);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment