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

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Do not resolve minimized numbers from cache
If we try to resolve a minimized number that we have not previously
queried matches for, then do not resolve to any contact that happens
to be in tha cache that matches that number - there may be a better
match that we should query for.

Once we have queried a specific number, or set the cache to fetch all
numbers, it is safe to resolve from the content of the cache.
  • Loading branch information
matthewvogt committed Oct 24, 2013
1 parent 329e46b commit b9d4941
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/seasidecache.cpp
Expand Up @@ -849,7 +849,15 @@ SeasideCache::CacheItem *SeasideCache::itemByPhoneNumber(const QString &number,
}
}

return instancePtr->itemMatchingPhoneNumber(minimizePhoneNumber(normalized), normalized, requireComplete);
const QString minimized(minimizePhoneNumber(normalized));
if (((instancePtr->m_fetchTypes & SeasideCache::FetchPhoneNumber) == 0) &&
!instancePtr->m_resolvedPhoneNumbers.contains(minimized)) {
// We haven't previously queried this number, so there may be more matches than any
// that we already have cached; return 0 to force a query
return 0;
}

return instancePtr->itemMatchingPhoneNumber(minimized, normalized, requireComplete);
}

SeasideCache::CacheItem *SeasideCache::itemByEmailAddress(const QString &email, bool requireComplete)
Expand Down Expand Up @@ -2309,6 +2317,11 @@ void SeasideCache::requestStateChanged(QContactAbstractRequest::State state)
} else {
// Result of a specific query
if (m_activeResolve) {
if (m_activeResolve->first == QString()) {
// We have now queried this phone number
m_resolvedPhoneNumbers.insert(minimizePhoneNumber(m_activeResolve->second));
}

CacheItem *item = 0;
const QList<QContact> &resolvedContacts(m_fetchRequest.contacts());
if (!resolvedContacts.isEmpty()) {
Expand Down Expand Up @@ -2611,6 +2624,11 @@ void SeasideCache::keepPopulated(quint32 fetchTypes)
m_fetchTypes |= fetchTypes;
m_fetchTypesChanged = true;
requestUpdate();

if ((m_fetchTypes & SeasideCache::FetchPhoneNumber) != 0) {
// We don't need to check resolved numbers any further
m_resolvedPhoneNumbers.clear();
}
}

if (!m_keepPopulated) {
Expand Down
1 change: 1 addition & 0 deletions src/seasidecache.h
Expand Up @@ -498,6 +498,7 @@ private slots:
QList<ResolveData> m_resolveAddresses;
QList<ResolveData> m_unknownAddresses;
const ResolveData *m_activeResolve;
QSet<QString> m_resolvedPhoneNumbers;

QElapsedTimer m_timer;
QElapsedTimer m_fetchPostponed;
Expand Down

0 comments on commit b9d4941

Please sign in to comment.