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] Update section bucket index cache after deletions. Cont…
…ributes to JB#46496

When a contact is deleted, we need to recalculate the section bucket
index cache as that contact may have been the only contact in a given
section bucket (display label group).

However, since updating the section bucket index cache is an expensive
operation, we should only do this once per bulk deletion, so this
commit also adds support for bulk deletion operations.
  • Loading branch information
Chris Adams committed Jul 3, 2019
1 parent 346cbb2 commit c7112da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/seasidecache.cpp
Expand Up @@ -1024,19 +1024,35 @@ void SeasideCache::contactDataChanged(quint32 iid, FilterType filter)

bool SeasideCache::removeContact(const QContact &contact)
{
QContactId id = apiId(contact);
if (!validId(id))
return false;
return removeContacts(QList<QContact>() << contact);
}

bool SeasideCache::removeContacts(const QList<QContact> &contacts)
{
bool allSucceeded = true;
QSet<QString> modifiedDisplayLabelGroups;
for (const QContact &contact : contacts) {
const QContactId id = apiId(contact);
if (!validId(id)) {
allSucceeded = false;
continue;
}

instancePtr->m_contactsToRemove.append(id);
instancePtr->m_contactsToRemove.append(id);

quint32 iid = internalId(id);
instancePtr->removeContactData(iid, FilterFavorites);
instancePtr->removeContactData(iid, FilterOnline);
instancePtr->removeContactData(iid, FilterAll);
quint32 iid = internalId(id);
instancePtr->removeContactData(iid, FilterFavorites);
instancePtr->removeContactData(iid, FilterOnline);
instancePtr->removeContactData(iid, FilterAll);

const QString group(displayLabelGroup(existingItem(iid)));
instancePtr->removeFromContactDisplayLabelGroup(iid, group, &modifiedDisplayLabelGroups);
}

instancePtr->notifyDisplayLabelGroupsChanged(modifiedDisplayLabelGroups);
instancePtr->updateSectionBucketIndexCaches();
instancePtr->requestUpdate();
return true;
return allSucceeded;
}

void SeasideCache::removeContactData(quint32 iid, FilterType filter)
Expand All @@ -1051,13 +1067,6 @@ void SeasideCache::removeContactData(quint32 iid, FilterType filter)

m_contacts[filter].removeAt(row);

if (filter == FilterAll) {
const QString group(displayLabelGroup(existingItem(iid)));
QSet<QString> modifiedDisplayLabelGroups;
removeFromContactDisplayLabelGroup(iid, group, &modifiedDisplayLabelGroups);
notifyDisplayLabelGroupsChanged(modifiedDisplayLabelGroups);
}

for (int i = 0; i < models.count(); ++i)
models.at(i)->sourceItemsRemoved();
}
Expand Down Expand Up @@ -1913,6 +1922,8 @@ bool SeasideCache::event(QEvent *event)
m_people.erase(cacheItem);
}
}

updateSectionBucketIndexCaches();
}
}
return true;
Expand Down
1 change: 1 addition & 0 deletions src/seasidecache.h
Expand Up @@ -308,6 +308,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject

static bool saveContact(const QContact &contact);
static bool removeContact(const QContact &contact);
static bool removeContacts(const QList<QContact> &contacts);

static void aggregateContacts(const QContact &contact1, const QContact &contact2);
static void disaggregateContacts(const QContact &contact1, const QContact &contact2);
Expand Down

0 comments on commit c7112da

Please sign in to comment.