diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index edee2cc..2f3298e 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -2311,21 +2311,35 @@ void SeasideCache::applyPendingContactUpdates() const bool partialFetch = !detailTypes.isEmpty(); QList &appendedContacts((*it).second); - appendContacts(appendedContacts, type, partialFetch, detailTypes); - - m_contactsToAppend.erase(it); - - // This list has been processed - have we finished populating the group? - if (type == FilterFavorites && (m_populateProgress != FetchFavorites)) { - makePopulated(FilterFavorites); - qDebug() << "Favorites queried in" << m_timer.elapsed() << "ms"; - } else if (type == FilterAll && (m_populateProgress != FetchMetadata)) { - makePopulated(FilterNone); - makePopulated(FilterAll); - qDebug() << "All queried in" << m_timer.elapsed() << "ms"; - } else if (type == FilterOnline && (m_populateProgress != FetchOnline)) { - makePopulated(FilterOnline); - qDebug() << "Online queried in" << m_timer.elapsed() << "ms"; + + const int maxBatchSize = 200; + const int minBatchSize = 50; + + if (appendedContacts.count() < maxBatchSize) { + // For a small number of contacts, append all at once + appendContacts(appendedContacts, type, partialFetch, detailTypes); + appendedContacts.clear(); + } else { + // Append progressively in batches + appendContacts(appendedContacts.mid(0, minBatchSize), type, partialFetch, detailTypes); + appendedContacts = appendedContacts.mid(minBatchSize); + } + + if (appendedContacts.isEmpty()) { + m_contactsToAppend.erase(it); + + // This list has been processed - have we finished populating the group? + if (type == FilterFavorites && (m_populateProgress != FetchFavorites)) { + makePopulated(FilterFavorites); + qDebug() << "Favorites queried in" << m_timer.elapsed() << "ms"; + } else if (type == FilterAll && (m_populateProgress != FetchMetadata)) { + makePopulated(FilterNone); + makePopulated(FilterAll); + qDebug() << "All queried in" << m_timer.elapsed() << "ms"; + } else if (type == FilterOnline && (m_populateProgress != FetchOnline)) { + makePopulated(FilterOnline); + qDebug() << "Online queried in" << m_timer.elapsed() << "ms"; + } } } else { QList, QList > >::iterator it = m_contactsToUpdate.begin();