Skip to content

Commit

Permalink
[contacts] Resolve phone numbers etc. to aggregate contacts rather th…
Browse files Browse the repository at this point in the history
…an constituents. JB#51530

Only index details for aggregate contacts. The model classes
present aggregates rather than constituents, and same with any
views that look up contacts for display, so the cache should
resolve phone/email/accounts to aggregates.

Constituents are only used for modifications and deletions and in
those cases they should be referred to by ID instead of via detail
resolution lookup.
  • Loading branch information
Bea Lam committed Oct 14, 2020
1 parent ed2d0c1 commit 2e453c5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/seasidecache.cpp
Expand Up @@ -2298,6 +2298,11 @@ void SeasideCache::resolveUnknownAddresses(const QString &first, const QString &

bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QContact &contact, quint32 iid, const QSet<QContactDetail::DetailType> &queryDetailTypes, CacheItem *item)
{
if (oldContact.collectionId() != aggregateCollectionId()
&& contact.collectionId() != aggregateCollectionId()) {
return false;
}

bool modified = false;

QSet<StringPair> oldAddresses;
Expand Down Expand Up @@ -2325,8 +2330,10 @@ bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QCont

CachedPhoneNumber cachedPhoneNumber(normalizePhoneNumber(phoneNumber.number()), iid);

if (!m_phoneNumberIds.contains(address.second, cachedPhoneNumber))
m_phoneNumberIds.insert(address.second, cachedPhoneNumber);
if (contact.collectionId() == aggregateCollectionId()) {
if (!m_phoneNumberIds.contains(address.second, cachedPhoneNumber))
m_phoneNumberIds.insert(address.second, cachedPhoneNumber);
}
}
}

Expand Down Expand Up @@ -2357,7 +2364,9 @@ bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QCont
resolveUnknownAddresses(address.first, address.second, item);
}

m_emailAddressIds[address.first] = iid;
if (contact.collectionId() == aggregateCollectionId()) {
m_emailAddressIds[address.first] = iid;
}
}

if (!oldAddresses.isEmpty()) {
Expand Down Expand Up @@ -2389,7 +2398,9 @@ bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QCont
resolveUnknownAddresses(address.first, address.second, item);
}

m_onlineAccountIds[address] = iid;
if (contact.collectionId() == aggregateCollectionId()) {
m_onlineAccountIds[address] = iid;
}
hasValid = true;
}

Expand Down Expand Up @@ -3393,6 +3404,8 @@ void SeasideCache::resolveAddress(ResolveListener *listener, const QString &firs
this, SLOT(addressRequestStateChanged(QContactAbstractRequest::State)));
m_resolveAddresses[request] = data;
m_pendingResolve.insert(data);

request->setFilter(request->filter() & aggregateFilter());
request->start();
}
}
Expand Down Expand Up @@ -3441,6 +3454,9 @@ SeasideCache::CacheItem *SeasideCache::itemMatchingPhoneNumber(const QString &nu
CacheItem *matchItem = 0;
for (QHash<QString, quint32>::const_iterator matchingIt = possibleMatches.begin(); matchingIt != possibleMatches.end(); ++matchingIt) {
if (CacheItem *item = existingItem(*matchingIt)) {
if (item->contact.collectionId() != aggregateCollectionId()) {
continue;
}
int matchLength = bestPhoneNumberMatchLength(item->contact, normalized);
if (matchLength > bestMatchLength) {
bestMatchLength = matchLength;
Expand Down

0 comments on commit 2e453c5

Please sign in to comment.