Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
[libcontacts] Append contacts in large batches
Browse files Browse the repository at this point in the history
Batched append slows down the overall throughput, but is necessary
to give interactivity during startup with huge contact counts. With
10000 contacts, the penalty is less than 10% overall, and the app
remains usable during the append period.
  • Loading branch information
matthewvogt committed Jan 9, 2014
1 parent 9c48a0d commit 82e2289
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/seasidecache.cpp
Expand Up @@ -2311,21 +2311,35 @@ void SeasideCache::applyPendingContactUpdates()
const bool partialFetch = !detailTypes.isEmpty();

QList<QContact> &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<QPair<QSet<DetailTypeId>, QList<QContact> > >::iterator it = m_contactsToUpdate.begin();
Expand Down

0 comments on commit 82e2289

Please sign in to comment.