[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [discover/Plasma/5.12] libdiscover/UpdateModel: Limit how often we refresh the size of the updates s
From:       Aleix Pol <null () kde ! org>
Date:       2018-05-30 23:44:35
Message-ID: E1fOAlf-00040a-2X () code ! kde ! org
[Download RAW message or body]

Git commit c01a0cee7ac60f7ec26e0710df6bbb1bcfddd889 by Aleix Pol.
Committed on 30/05/2018 at 23:44.
Pushed by apol into branch 'Plasma/5.12'.

Limit how often we refresh the size of the updates set

PackageKit will update every resource separately after the initial fetch
and this would recompute the update size for each.
Now its done once per update, saving some freeze time.

M  +7    -1    libdiscover/UpdateModel/UpdateModel.cpp
M  +2    -0    libdiscover/UpdateModel/UpdateModel.h

https://commits.kde.org/discover/c01a0cee7ac60f7ec26e0710df6bbb1bcfddd889

diff --git a/libdiscover/UpdateModel/UpdateModel.cpp \
b/libdiscover/UpdateModel/UpdateModel.cpp index 1f229133..8b04a966 100644
--- a/libdiscover/UpdateModel/UpdateModel.cpp
+++ b/libdiscover/UpdateModel/UpdateModel.cpp
@@ -22,6 +22,7 @@
 
 // Qt includes
 #include <QFont>
+#include <QTimer>
 #include <QDebug>
 
 // KDE includes
@@ -36,12 +37,17 @@
 
 UpdateModel::UpdateModel(QObject *parent)
     : QAbstractListModel(parent)
+    , m_updateSizeTimer(new QTimer(this))
     , m_updates(nullptr)
 {
     connect(ResourcesModel::global(), &ResourcesModel::fetchingChanged, this, \
                &UpdateModel::activityChanged);
     connect(ResourcesModel::global(), &ResourcesModel::updatesCountChanged, this, \
                &UpdateModel::activityChanged);
     connect(ResourcesModel::global(), &ResourcesModel::resourceDataChanged, this, \
                &UpdateModel::resourceDataChanged);
     connect(this, &UpdateModel::toUpdateChanged, this, \
&UpdateModel::updateSizeChanged); +
+    m_updateSizeTimer->setInterval(100);
+    m_updateSizeTimer->setSingleShot(true);
+    connect(m_updateSizeTimer, &QTimer::timeout, this, \
&UpdateModel::updateSizeChanged);  }
 
 UpdateModel::~UpdateModel() = default;
@@ -310,6 +316,6 @@ void UpdateModel::resourceDataChanged(AbstractResource* res, \
const QVector<QByte  dataChanged(index, index, {SizeRole, VersionRole});
     else if (properties.contains("size")) {
         dataChanged(index, index, {SizeRole});
-        Q_EMIT updateSizeChanged();
+        m_updateSizeTimer->start();
     }
 }
diff --git a/libdiscover/UpdateModel/UpdateModel.h \
b/libdiscover/UpdateModel/UpdateModel.h index fc5dd1a4..4df37b85 100644
--- a/libdiscover/UpdateModel/UpdateModel.h
+++ b/libdiscover/UpdateModel/UpdateModel.h
@@ -24,6 +24,7 @@
 #include <QAbstractListModel>
 #include "discovercommon_export.h"
 
+class QTimer;
 class ResourcesUpdatesModel;
 class AbstractResource;
 class UpdateItem;
@@ -91,6 +92,7 @@ private:
     void resourceHasProgressed(AbstractResource* res, qreal progress);
     void activityChanged();
 
+    QTimer* const m_updateSizeTimer;
     QVector<UpdateItem*> m_updateItems;
     ResourcesUpdatesModel* m_updates;
     QList<AbstractResource*> m_resources;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic