Commit d8690b09 authored by mvogt's avatar mvogt

[libcontacts] Use internal IDs for contact sequence management

The strings used in Qt5Contact contact IDs are very slow to compare.
parent 300a66ed
......@@ -279,6 +279,18 @@ bool ignoreContactForNameGroups(const QContact &contact)
return (syncTarget.syncTarget() != aggregate);
}
QList<quint32> internalIds(const QList<SeasideCache::ContactIdType> &ids)
{
QList<quint32> rv;
rv.reserve(ids.count());
foreach (const SeasideCache::ContactIdType &id, ids) {
rv.append(SeasideCache::internalId(id));
}
return rv;
}
}
SeasideCache *SeasideCache::instancePtr = 0;
......@@ -829,7 +841,7 @@ void SeasideCache::contactDataChanged(const ContactIdType &contactId)
void SeasideCache::contactDataChanged(const ContactIdType &contactId, FilterType filter)
{
int row = m_contacts[filter].indexOf(contactId);
int row = contactIndex(internalId(contactId), filter);
if (row != -1) {
QList<ListModel *> &models = m_models[filter];
for (int i = 0; i < models.count(); ++i) {
......@@ -856,7 +868,7 @@ bool SeasideCache::removeContact(const QContact &contact)
void SeasideCache::removeContactData(
const ContactIdType &contactId, FilterType filter)
{
int row = m_contacts[filter].indexOf(contactId);
int row = contactIndex(internalId(contactId), filter);
if (row == -1)
return;
......@@ -864,7 +876,7 @@ void SeasideCache::removeContactData(
for (int i = 0; i < models.count(); ++i)
models.at(i)->sourceAboutToRemoveItems(row, row);
m_contacts[filter].remove(row);
m_contacts[filter].removeAt(row);
if (filter == FilterAll) {
const QString group(nameGroup(existingItem(contactId)));
......@@ -905,7 +917,7 @@ bool SeasideCache::fetchMergeCandidates(const QContact &contact)
return true;
}
const QVector<SeasideCache::ContactIdType> *SeasideCache::contacts(FilterType type)
const QList<quint32> *SeasideCache::contacts(FilterType type)
{
return &instancePtr->m_contacts[type];
}
......@@ -1801,7 +1813,7 @@ void SeasideCache::contactIdsAvailable()
}
if (m_syncFilter != FilterNone) {
synchronizeList(this, m_contacts[m_syncFilter], m_cacheIndex, m_contactIdRequest.ids(), m_queryIndex);
synchronizeList(this, m_contacts[m_syncFilter], m_cacheIndex, internalIds(m_contactIdRequest.ids()), m_queryIndex);
}
}
......@@ -1826,7 +1838,7 @@ void SeasideCache::relationshipsAvailable()
void SeasideCache::removeRange(FilterType filter, int index, int count)
{
QVector<ContactIdType> &cacheIds = m_contacts[filter];
QList<quint32> &cacheIds = m_contacts[filter];
QList<ListModel *> &models = m_models[filter];
for (int i = 0; i < models.count(); ++i)
......@@ -1836,16 +1848,16 @@ void SeasideCache::removeRange(FilterType filter, int index, int count)
for (int i = 0; i < count; ++i) {
if (filter == FilterAll) {
const ContactIdType apiId = cacheIds.at(index);
m_expiredContacts[apiId] -= 1;
const quint32 iid = cacheIds.at(index);
m_expiredContacts[apiId(iid)] -= 1;
const QString group(nameGroup(existingItem(apiId)));
const QString group(nameGroup(existingItem(iid)));
if (!group.isNull()) {
removeFromContactNameGroup(internalId(apiId), group, &modifiedNameGroups);
removeFromContactNameGroup(iid, group, &modifiedNameGroups);
}
}
cacheIds.remove(index);
cacheIds.removeAt(index);
}
for (int i = 0; i < models.count(); ++i)
......@@ -1854,32 +1866,28 @@ void SeasideCache::removeRange(FilterType filter, int index, int count)
notifyNameGroupsChanged(modifiedNameGroups);
}
int SeasideCache::insertRange(
FilterType filter,
int index,
int count,
const QList<ContactIdType> &queryIds,
int queryIndex)
int SeasideCache::insertRange(FilterType filter, int index, int count, const QList<quint32> &queryIds, int queryIndex)
{
QVector<ContactIdType> &cacheIds = m_contacts[filter];
QList<quint32> &cacheIds = m_contacts[filter];
QList<ListModel *> &models = m_models[filter];
const ContactIdType selfId = m_manager.selfContactId();
const quint32 selfId = internalId(m_manager.selfContactId());
int end = index + count - 1;
for (int i = 0; i < models.count(); ++i)
models[i]->sourceAboutToInsertItems(index, end);
for (int i = 0; i < count; ++i) {
if (queryIds.at(queryIndex + i) == selfId)
quint32 iid = queryIds.at(queryIndex + i);
if (iid == selfId)
continue;
if (filter == FilterAll) {
const ContactIdType apiId = queryIds.at(queryIndex + i);
const ContactIdType apiId = SeasideCache::apiId(iid);
m_expiredContacts[apiId] += 1;
}
cacheIds.insert(index + i, queryIds.at(queryIndex + i));
cacheIds.insert(index + i, iid);
}
for (int i = 0; i < models.count(); ++i)
......@@ -1891,7 +1899,7 @@ int SeasideCache::insertRange(
void SeasideCache::appendContacts(const QList<QContact> &contacts, FilterType filterType, bool partialFetch)
{
if (!contacts.isEmpty()) {
QVector<ContactIdType> &cacheIds = m_contacts[filterType];
QList<quint32> &cacheIds = m_contacts[filterType];
QList<ListModel *> &models = m_models[filterType];
cacheIds.reserve(contacts.count());
......@@ -1906,10 +1914,10 @@ void SeasideCache::appendContacts(const QList<QContact> &contacts, FilterType fi
models.at(i)->sourceAboutToInsertItems(begin, end);
foreach (QContact contact, contacts) {
ContactIdType apiId = SeasideCache::apiId(contact);
quint32 iid = internalId(contact);
cacheIds.append(apiId);
cacheIds.append(iid);
CacheItem &cacheItem = m_people[iid];
// If we have already requested this contact as a favorite, don't update with fewer details
......@@ -2010,7 +2018,7 @@ void SeasideCache::requestStateChanged(QContactAbstractRequest::State state)
}
} else if (m_syncFilter != FilterNone) {
// We have completed fetching this filter set
completeSynchronizeList(this, m_contacts[m_syncFilter], m_cacheIndex, m_contactIdRequest.ids(), m_queryIndex);
completeSynchronizeList(this, m_contacts[m_syncFilter], m_cacheIndex, internalIds(m_contactIdRequest.ids()), m_queryIndex);
// Notify models of completed updates
QList<ListModel *> &models = m_models[m_syncFilter];
......@@ -2524,6 +2532,12 @@ void SeasideCache::resolveAddress(ResolveListener *listener, const QString &firs
requestUpdate();
}
int SeasideCache::contactIndex(quint32 iid, FilterType filterType)
{
const QList<quint32> &cacheIds(m_contacts[filterType]);
return cacheIds.indexOf(iid);
}
QContactRelationship SeasideCache::makeRelationship(const QString &type, const QContact &contact1, const QContact &contact2)
{
QContactRelationship relationship;
......
......@@ -57,7 +57,6 @@
#include <QBasicTimer>
#include <QSet>
#include <QVector>
#include <QElapsedTimer>
#include <QAbstractListModel>
......@@ -334,7 +333,7 @@ public:
static int importContacts(const QString &path);
static QString exportContacts();
static const QVector<ContactIdType> *contacts(FilterType filterType);
static const QList<quint32> *contacts(FilterType filterType);
static bool isPopulated(FilterType filterType);
static QString generateDisplayLabel(const QContact &contact, DisplayLabelOrder order = FirstNameFirst);
......@@ -346,8 +345,7 @@ public:
bool event(QEvent *event);
// For synchronizeLists()
int insertRange(int index, int count, const QList<ContactIdType> &source, int sourceIndex) {
return insertRange(m_syncFilter, index, count, source, sourceIndex); }
int insertRange(int index, int count, const QList<quint32> &source, int sourceIndex) { return insertRange(m_syncFilter, index, count, source, sourceIndex); }
int removeRange(int index, int count) { removeRange(m_syncFilter, index, count); return 0; }
protected:
......@@ -402,12 +400,7 @@ private:
void reportItemUpdated(CacheItem *item);
void removeRange(FilterType filter, int index, int count);
int insertRange(
FilterType filter,
int index,
int count,
const QList<ContactIdType> &queryIds,
int queryIndex);
int insertRange(FilterType filter, int index, int count, const QList<quint32> &queryIds, int queryIndex);
void contactDataChanged(const ContactIdType &contactId);
void contactDataChanged(const ContactIdType &contactId, FilterType filter);
......@@ -423,8 +416,12 @@ private:
void resolveAddress(ResolveListener *listener, const QString &first, const QString &second, bool requireComplete);
int contactIndex(quint32 iid, FilterType filter);
static QContactRelationship makeRelationship(const QString &type, const QContact &contact1, const QContact &contact2);
QList<quint32> m_contacts[FilterTypesCount];
QBasicTimer m_expiryTimer;
QBasicTimer m_fetchTimer;
QHash<quint32, CacheItem> m_people;
......@@ -445,7 +442,6 @@ private:
QScopedPointer<SeasideNameGrouper> m_nameGrouper;
QList<SeasideNameGroupChangeListener*> m_nameGroupChangeListeners;
QList<ChangeListener*> m_changeListeners;
QVector<ContactIdType> m_contacts[FilterTypesCount];
QList<ListModel *> m_models[FilterTypesCount];
QSet<QObject *> m_users;
QHash<ContactIdType,int> m_expiredContacts;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment