[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:13 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=a7b9889

The following commit has been merged in the master branch:
commit a7b988918ef0e4b33812dfb96401a93e7391c01a
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Mon Apr 21 00:25:17 2014 +0200

    Remove internal countContacts function
    
    This method counted the contacts in a group every time a contact in that
    group changed. This meant on every insertion we would loop through the
    entire set of contacts to make the new count.
    
    Assuming all contacts come online we end up making contacts^2 calls to
    data() which is obviously really slow. On my system KPeople::data()
    showed over 300,000 calls on load
    
    Instead strip this code and re-insert a simple filter at the contact
    list level (see patch to contact list)
---
 KTp/Models/contacts-filter-model.cpp | 93 ++----------------------------------
 KTp/Models/contacts-filter-model.h   |  4 +-
 2 files changed, 5 insertions(+), 92 deletions(-)

diff --git a/KTp/Models/contacts-filter-model.cpp b/KTp/Models/contacts-filter-model.cpp
index 617d3aa..2fc4a82 100644
--- a/KTp/Models/contacts-filter-model.cpp
+++ b/KTp/Models/contacts-filter-model.cpp
@@ -74,13 +74,9 @@ public:
     bool filterAcceptsContact(const QModelIndex &index) const;
     bool filterAcceptsGroup(const QModelIndex &index);
 
-    void countContacts(const QModelIndex &sourceParent);
-
     void sourceModelParentIndexChanged(const QModelIndex &sourceIndex);
     void sourceModelIndexChanged(const QModelIndex &sourceIndex);
 
-    QHash<QString, int> m_onlineContactsCounts;
-    QHash<QString, int> m_totalContactsCounts;
     bool m_qtSortHack;
 };
 
@@ -338,84 +334,18 @@ bool ContactsFilterModel::Private::filterAcceptsContact(const QModelIndex &index
 
 bool ContactsFilterModel::Private::filterAcceptsGroup(const QModelIndex &index)
 {
-    QString groupName = index.data(KTp::IdRole).toString();
-
-    if (presenceTypeFilterFlags != DoNotFilterByPresence) {
-        // If there is no cached value, create one
-        if (!m_onlineContactsCounts.contains(groupName)) {
-            countContacts(index);
-        }
-
-        // Don't accept groups with no online contacts
-        if (m_onlineContactsCounts.value(groupName) == 0) {
-            return false;
-        }
-    }
-    else {
-        // If there is no cached value, create one
-        if (!m_totalContactsCounts.contains(groupName)) {
-            countContacts(index);
-        }
-
-        // Don't accept groups with no total contacts
-        if (m_totalContactsCounts.value(groupName) == 0) {
-            return false;
-        }
-    }
     return true;
 }
 
-void ContactsFilterModel::Private::countContacts(const QModelIndex &sourceParent)
-{
-    QString key = sourceParent.data(KTp::IdRole).toString();
-
-    // Count the online contacts
-    int tmpCounter = 0;
-
-    for (int i = 0; i < q->sourceModel()->rowCount(sourceParent); ++i) {
-        QModelIndex child = q->sourceModel()->index(i, 0, sourceParent);
-
-        // We want all online contacts that are accepted by the filter
-        if (q->filterAcceptsRow(child.row(), sourceParent)
-            && child.data(KTp::ContactPresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
-            && child.data(KTp::ContactPresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
-            tmpCounter++;
-        }
-    }
-
-    m_onlineContactsCounts.insert(key, tmpCounter);
-
-    // Now count the total contacts accepted by the filter (but ignore presence filter).
-    // Save the presenceTypeFilterFlags to reapply them later, because we need to disable
-    // presence filtering to get the right numbers
-    PresenceTypeFilterFlags saved = q->presenceTypeFilterFlags();
-    presenceTypeFilterFlags = ContactsFilterModel::DoNotFilterByPresence;
-
-    tmpCounter = 0;
-    for (int i = 0; i < q->sourceModel()->rowCount(sourceParent); ++i) {
-        QModelIndex child = q->sourceModel()->index(i, 0, sourceParent);
-        if (q->filterAcceptsRow(child.row(), sourceParent)) {
-            tmpCounter++;
-        }
-    }
-
-    // Restore the saved presenceTypeFilterFlags
-    presenceTypeFilterFlags = saved;
-
-    m_totalContactsCounts.insert(key, tmpCounter);
-}
-
 void ContactsFilterModel::Private::sourceModelParentIndexChanged(const QModelIndex &sourceIndex)
 {
     //if parent is a group heading
     if (sourceIndex.isValid() &&
         (sourceIndex.data(KTp::RowTypeRole).toInt() == KTp::GroupRowType ||
         sourceIndex.data(KTp::RowTypeRole).toInt() == KTp::AccountRowType)) {
-        countContacts(sourceIndex);
 
-        //emit that the source parent changed, this way it will go through "filterAcceptsRow" again
-        //and filter empty groups
-        QMetaObject::invokeMethod(q->sourceModel(), "dataChanged", Q_ARG(QModelIndex, sourceIndex), Q_ARG(QModelIndex, sourceIndex));
+
+        q->dataChanged(q->mapFromSource(sourceIndex), q->mapFromSource(sourceIndex));
     }
 }
 
@@ -450,17 +380,9 @@ QVariant ContactsFilterModel::data(const QModelIndex &index, int role) const
     }
 
     if (role == KTp::HeaderOnlineUsersRole) {
-        const QString &key = sourceIndex.data(KTp::IdRole).toString();
-        if (!d->m_onlineContactsCounts.contains(key)) {
-            d->countContacts(sourceIndex);
-        }
-        return d->m_onlineContactsCounts.value(key);
+        return rowCount(index);
     } else if (role == KTp::HeaderTotalUsersRole) {
-        const QString &key = sourceIndex.data(KTp::IdRole).toString();
-        if (!d->m_totalContactsCounts.contains(key)) {
-            d->countContacts(sourceIndex);
-        }
-        return d->m_totalContactsCounts.value(key);
+        return sourceModel()->rowCount(sourceIndex);
     }
 
     // In all other cases just delegate it to the source model
@@ -481,10 +403,6 @@ void ContactsFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
                 this, SLOT(sourceModelParentIndexChanged(QModelIndex)));
     }
 
-    // Clear all cached values as they aren't valid anymore because the source model changed.
-    d->m_onlineContactsCounts.clear();
-    d->m_totalContactsCounts.clear();
-
     if (sourceModel) {
         QSortFilterProxyModel::setSourceModel(sourceModel);
 
@@ -502,9 +420,6 @@ void ContactsFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
 
 void ContactsFilterModel::invalidateFilter()
 {
-    // Clear all cached values as they aren't valid anymore because the filter changed.
-    d->m_onlineContactsCounts.clear();
-    d->m_totalContactsCounts.clear();
     QSortFilterProxyModel::invalidateFilter();
 }
 
diff --git a/KTp/Models/contacts-filter-model.h b/KTp/Models/contacts-filter-model.h
index bccc6f6..7c46d7a 100644
--- a/KTp/Models/contacts-filter-model.h
+++ b/KTp/Models/contacts-filter-model.h
@@ -306,9 +306,7 @@ private:
 
     Q_PRIVATE_SLOT(d, void sourceModelParentIndexChanged(const QModelIndex &sourceIndex))
     Q_PRIVATE_SLOT(d, void sourceModelIndexChanged(const QModelIndex &sourceIndex))
-    Q_PRIVATE_SLOT(d, void countContacts(const QModelIndex &index))
 };
-
 } //namespace
 
-#endif // ACCOUNTFILTERMODEL_H
+#endif // CONTACTSFILTERMODEL_H

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list