Skip to content

Commit

Permalink
Performance: reduce the detail types fetched during populate step
Browse files Browse the repository at this point in the history
All details other than timestamp and status flags were moved out
of the main contacts table in qtcontacts-sqlite recently.
This means that it is relatively expensive to query detail types
such as gender/favorite/synctarget etc if they are not required.

Note that we still fetch the gender when populating the "all" list,
as we can use this data when determining valid merge targets.
  • Loading branch information
Chris Adams authored and Bea Lam committed Sep 24, 2020
1 parent 6c222eb commit de4d518
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
40 changes: 27 additions & 13 deletions lib/seasidecache.cpp
Expand Up @@ -220,17 +220,21 @@ QContactFetchHint presenceFetchHint()
return fetchHint;
}

DetailList displayDetails()
{
DetailList types;
types << detailType<QContactName>()
<< detailType<QContactNickname>()
<< detailType<QContactDisplayLabel>();
return types;
}

DetailList contactsTableDetails()
{
DetailList types;

// These details are reported in every query
types << detailType<QContactSyncTarget>() <<
detailType<QContactName>() <<
detailType<QContactDisplayLabel>() <<
detailType<QContactFavorite>() <<
detailType<QContactTimestamp>() <<
detailType<QContactGender>() <<
types << detailType<QContactTimestamp>() <<
detailType<QContactStatusFlags>();

return types;
Expand All @@ -243,8 +247,9 @@ QContactFetchHint metadataFetchHint(quint32 fetchTypes = 0)
// Include all detail types which come from the main contacts table
DetailList types(contactsTableDetails());

// Include nickname, as some contacts have no other name
types << detailType<QContactNickname>();
// Include common details used for display purposes
// (including nickname, as some contacts have no other name)
types << displayDetails();

if (fetchTypes & SeasideCache::FetchAccountUri) {
types << detailType<QContactOnlineAccount>();
Expand All @@ -261,6 +266,12 @@ QContactFetchHint metadataFetchHint(quint32 fetchTypes = 0)
if (fetchTypes & SeasideCache::FetchAvatar) {
types << detailType<QContactAvatar>();
}
if (fetchTypes & SeasideCache::FetchFavorite) {
types << detailType<QContactFavorite>();
}
if (fetchTypes & SeasideCache::FetchGender) {
types << detailType<QContactGender>();
}

setDetailTypesHint(fetchHint, types);
return fetchHint;
Expand All @@ -277,11 +288,8 @@ QContactFetchHint onlineFetchHint(quint32 fetchTypes = 0)

QContactFetchHint favoriteFetchHint(quint32 fetchTypes = 0)
{
QContactFetchHint fetchHint(onlineFetchHint(fetchTypes));

// We also need avatar info
setDetailTypesHint(fetchHint, detailTypesHint(fetchHint) << detailType<QContactAvatar>());
return fetchHint;
return onlineFetchHint(fetchTypes | SeasideCache::FetchAvatar | SeasideCache::FetchFavorite);
}

QContactFetchHint extendedMetadataFetchHint(quint32 fetchTypes)
Expand All @@ -306,6 +314,12 @@ QContactFetchHint extendedMetadataFetchHint(quint32 fetchTypes)
if (fetchTypes & SeasideCache::FetchAvatar) {
types << detailType<QContactAvatar>();
}
if (fetchTypes & SeasideCache::FetchFavorite) {
types << detailType<QContactFavorite>();
}
if (fetchTypes & SeasideCache::FetchGender) {
types << detailType<QContactGender>();
}

setDetailTypesHint(fetchHint, types);
return fetchHint;
Expand Down Expand Up @@ -1614,7 +1628,7 @@ void SeasideCache::startRequest(bool *idleProcessing)
// Request the metadata of all contacts (only data from the primary table, and any
// other details required to determine whether the contacts matches the filter)
m_fetchRequest.setFilter(allFilter());
m_fetchRequest.setFetchHint(metadataFetchHint(m_fetchTypes));
m_fetchRequest.setFetchHint(metadataFetchHint(m_fetchTypes | SeasideCache::FetchGender));
m_fetchRequest.setSorting(m_sortOrder);
qDebug() << "Starting metadata query at" << m_timer.elapsed() << "ms";
m_fetchRequest.start();
Expand Down
6 changes: 5 additions & 1 deletion lib/seasidecache.h
Expand Up @@ -92,11 +92,15 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
FetchEmailAddress = (1 << 2),
FetchOrganization = (1 << 3),
FetchAvatar = (1 << 4),
FetchFavorite = (1 << 5),
FetchGender = (1 << 6),
FetchTypesMask = (FetchAccountUri |
FetchPhoneNumber |
FetchEmailAddress |
FetchOrganization |
FetchAvatar)
FetchAvatar |
FetchFavorite |
FetchGender)
};

enum DisplayLabelOrder {
Expand Down

0 comments on commit de4d518

Please sign in to comment.