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)
}
instancePtr->requestUpdate();
instancePtr->updateSectionBucketIndexCaches();
return true;
}
......@@ -2034,6 +2035,7 @@ void SeasideCache::dataChanged()
model->updateGroupProperty();
model->sourceItemsChanged();
model->sourceDataChanged(0, m_contacts[i].size());
model->updateSectionBucketIndexCache();
}
}
......@@ -2342,6 +2344,7 @@ void SeasideCache::contactsAvailable()
if (contacts.count() == 1 || request == &m_fetchByIdRequest) {
// Process these results immediately
applyContactUpdates(contacts, queryDetailTypes);
updateSectionBucketIndexCaches(); // note: can cause out-of-order since this doesn't result in refresh request. TODO: remove this line?
} else {
// 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();
......@@ -2406,6 +2409,7 @@ void SeasideCache::applyPendingContactUpdates()
makePopulated(FilterOnline);
qDebug() << "Online queried in" << m_timer.elapsed() << "ms";
}
updateSectionBucketIndexCaches();
}
} else {
QList<QPair<QSet<QContactDetail::DetailType>, QList<QContact> > >::iterator it = m_contactsToUpdate.begin();
......@@ -2419,6 +2423,17 @@ void SeasideCache::applyPendingContactUpdates()
if (updatedContacts.isEmpty()) {
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:
virtual void updateDisplayLabelOrder() = 0;
virtual void updateSortProperty() = 0;
virtual void updateGroupProperty() = 0;
virtual void updateSectionBucketIndexCache() = 0;
};
struct ResolveListener
......@@ -377,6 +379,7 @@ private:
void updateContacts(const QList<QContactId> &contactIds, QList<QContactId> *updateList);
void applyPendingContactUpdates();
void applyContactUpdates(const QList<QContact> &contacts, const QSet<QContactDetail::DetailType> &queryDetailTypes);
void updateSectionBucketIndexCaches();
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);
......
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