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

Commit

Permalink
Merge pull request #31 from matthewvogt/retrieve-loop
Browse files Browse the repository at this point in the history
[libcontacts] Prevent retrieval loop
  • Loading branch information
matthewvogt committed Sep 9, 2013
2 parents a53bc26 + 5133ce4 commit ddaa210
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
36 changes: 21 additions & 15 deletions src/seasidecache.cpp
Expand Up @@ -1163,9 +1163,9 @@ bool SeasideCache::event(QEvent *event)
// Fetch the constituent information (even if they're already in the
// cache, because we don't update non-aggregates on change notifications)
#ifdef USING_QTPIM
m_fetchByIdRequest.setIds(m_constituentIds);
m_fetchByIdRequest.setIds(m_constituentIds.toList());
#else
m_fetchByIdRequest.setLocalIds(m_constituentIds);
m_fetchByIdRequest.setLocalIds(m_constituentIds.toList());
#endif
m_fetchByIdRequest.start();
} else if (!m_contactsToFetchConstituents.isEmpty() && !m_relationshipsFetchRequest.isActive()) {
Expand Down Expand Up @@ -1725,7 +1725,9 @@ void SeasideCache::notifyNameGroupsChanged(const QSet<QString> &groups)
void SeasideCache::contactIdsAvailable()
{
if (!m_contactsToFetchCandidates.isEmpty()) {
m_candidateIds.append(m_contactIdRequest.ids());
foreach (const ContactIdType &id, m_contactIdRequest.ids()) {
m_candidateIds.insert(id);
}
return;
}

Expand All @@ -1743,9 +1745,9 @@ void SeasideCache::relationshipsAvailable()
foreach (const QContactRelationship &rel, m_relationshipsFetchRequest.relationships()) {
if (rel.relationshipType() == aggregatesRelationship) {
#ifdef USING_QTPIM
m_constituentIds.append(apiId(rel.second()));
m_constituentIds.insert(apiId(rel.second()));
#else
m_constituentIds.append(rel.second().localId());
m_constituentIds.insert(rel.second().localId());
#endif
}
}
Expand Down Expand Up @@ -1871,24 +1873,28 @@ void SeasideCache::requestStateChanged(QContactAbstractRequest::State state)
bool activityCompleted = true;

if (request == &m_relationshipsFetchRequest) {
if (!m_contactsToFetchConstituents.isEmpty() && m_constituentIds.isEmpty()) {
// We didn't find any constituents - report the empty list
if (!m_contactsToFetchConstituents.isEmpty()) {
QContactId aggregateId = m_contactsToFetchConstituents.takeFirst();
if (!m_constituentIds.isEmpty()) {
m_contactsToLinkTo.append(aggregateId);
} else {
// We didn't find any constituents - report the empty list
#ifdef USING_QTPIM
CacheItem *cacheItem = itemById(aggregateId);
CacheItem *cacheItem = itemById(aggregateId);
#else
CacheItem *cacheItem = itemById(aggregateId.localId());
CacheItem *cacheItem = itemById(aggregateId.localId());
#endif
if (cacheItem->itemData) {
cacheItem->itemData->constituentsFetched(QList<int>());
}
if (cacheItem->itemData) {
cacheItem->itemData->constituentsFetched(QList<int>());
}

updateConstituentAggregations(cacheItem->apiId());
updateConstituentAggregations(cacheItem->apiId());
}
}
} else if (request == &m_fetchByIdRequest) {
if (!m_contactsToFetchConstituents.isEmpty()) {
if (!m_contactsToLinkTo.isEmpty()) {
// Report these results
QContactId aggregateId = m_contactsToFetchConstituents.takeFirst();
QContactId aggregateId = m_contactsToLinkTo.takeFirst();
#ifdef USING_QTPIM
CacheItem *cacheItem = itemById(aggregateId);
#else
Expand Down
5 changes: 3 additions & 2 deletions src/seasidecache.h
Expand Up @@ -437,6 +437,7 @@ private slots:
QList<ContactIdType> m_changedContacts;
QList<QContactId> m_contactsToFetchConstituents;
QList<QContactId> m_contactsToFetchCandidates;
QList<QContactId> m_contactsToLinkTo;
QList<QPair<ContactLinkRequest, ContactLinkRequest> > m_contactPairsToLink;
QList<QContactRelationship> m_relationshipsToSave;
QList<QContactRelationship> m_relationshipsToRemove;
Expand Down Expand Up @@ -483,8 +484,8 @@ private slots:
bool m_updatesPending;
bool m_refreshRequired;
bool m_contactsUpdated;
QList<ContactIdType> m_constituentIds;
QList<ContactIdType> m_candidateIds;
QSet<ContactIdType> m_constituentIds;
QSet<ContactIdType> m_candidateIds;

struct ResolveData {
QString first;
Expand Down

0 comments on commit ddaa210

Please sign in to comment.