summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Chernov <4ernov@gmail.com>2011-06-27 20:40:45 (GMT)
committerAlexey Chernov <4ernov@gmail.com>2011-06-28 20:38:28 (GMT)
commit6508fcfdc37d537301a578ecba302ffc3d0cf5f0 (patch)
tree87e222982275da6e06df66c99e0400b16eb01875
parentd55536324f7051cf40b05b36567a33d0e18e8fff (diff)
Speedup of Remember The Milk dataengine and libraryv4.6.5
Waste and duplicate HTTP requests removed, gaps between requests cleared. As a result RTM dataengine and library got speedup of approx. 2 - 3 times on a plasmoid startup and less speedup on processing common routines.
-rw-r--r--dataengines/rememberthemilk/listssource.cpp11
-rw-r--r--dataengines/rememberthemilk/listssource.h1
-rw-r--r--dataengines/rememberthemilk/rtmengine.cpp9
-rw-r--r--dataengines/rememberthemilk/taskssource.cpp13
-rw-r--r--dataengines/rememberthemilk/taskssource.h1
-rw-r--r--libs/rtm/request.cpp14
-rw-r--r--libs/rtm/session_p.h15
7 files changed, 42 insertions, 22 deletions
diff --git a/dataengines/rememberthemilk/listssource.cpp b/dataengines/rememberthemilk/listssource.cpp
index b8f45e8..df36ad7 100644
--- a/dataengines/rememberthemilk/listssource.cpp
+++ b/dataengines/rememberthemilk/listssource.cpp
@@ -40,7 +40,7 @@ ListsSource::ListsSource(RtmEngine* engine, RTM::Session* session)
timer.setInterval(1000*60*5); // 5 minute refresh. TODO: Make Configurable.
timer.start();
setObjectName("Lists");
- listsChanged();
+ loadCache();
}
ListsSource::~ListsSource()
@@ -69,12 +69,15 @@ void ListsSource::listChanged(RTM::List* list) {
void ListsSource::listsChanged() {
removeAllData();
-
+ loadCache();
+
+ checkForUpdate();
+}
+
+void ListsSource::loadCache() {
foreach(RTM::List *list, m_session->cachedLists()) {
setData(QString::number(list->id()), list->name());
}
-
- checkForUpdate();
}
#include "listssource.moc"
diff --git a/dataengines/rememberthemilk/listssource.h b/dataengines/rememberthemilk/listssource.h
index 60ec55d..29bbc00 100644
--- a/dataengines/rememberthemilk/listssource.h
+++ b/dataengines/rememberthemilk/listssource.h
@@ -48,6 +48,7 @@ public slots:
private slots:
void listsChanged();
void listChanged(RTM::List*);
+ void loadCache();
private:
RtmEngine *m_engine;
diff --git a/dataengines/rememberthemilk/rtmengine.cpp b/dataengines/rememberthemilk/rtmengine.cpp
index 46ecce9..784d7db 100644
--- a/dataengines/rememberthemilk/rtmengine.cpp
+++ b/dataengines/rememberthemilk/rtmengine.cpp
@@ -60,8 +60,13 @@ RtmEngine::~RtmEngine() {
bool RtmEngine::tokenCheck(bool success)
{
if (success) {
- session->refreshListsFromServer();
- session->refreshTasksFromServer();
+ if (sources().contains("Lists")) {
+ session->refreshListsFromServer();
+ }
+
+ if (sources().contains("Tasks")) {
+ session->refreshTasksFromServer();
+ }
}
return updateSourceEvent("Auth");
}
diff --git a/dataengines/rememberthemilk/taskssource.cpp b/dataengines/rememberthemilk/taskssource.cpp
index 46dad35..612d9ec 100644
--- a/dataengines/rememberthemilk/taskssource.cpp
+++ b/dataengines/rememberthemilk/taskssource.cpp
@@ -42,7 +42,7 @@ TasksSource::TasksSource(RtmEngine* engine, RTM::Session* session)
timer.setInterval(1000*60*2); // 5 minute refresh. TODO: Make Configurable.
timer.start();
setObjectName("Tasks");
- tasksChanged();
+ loadCache();
}
TasksSource::~TasksSource()
@@ -64,9 +64,7 @@ void TasksSource::refresh()
void TasksSource::tasksChanged() {
removeAllData();
- kDebug() << "Updating Tasks. " << m_session->cachedTasks().count();
- foreach(RTM::Task* task, m_session->cachedTasks())
- setData(QString::number(task->id()), task->name()); // ids are unique, names are not
+ loadCache();
}
@@ -75,5 +73,12 @@ void TasksSource::taskChanged(RTM::Task* task) {
m_engine->updateTaskSource(QString::number(task->id()));
}
+void TasksSource::loadCache() {
+ kDebug() << "Updating Tasks. " << m_session->cachedTasks().count();
+ foreach(RTM::Task* task, m_session->cachedTasks()) {
+ setData(QString::number(task->id()), task->name()); // ids are unique, names are not
+ }
+}
+
#include "taskssource.moc"
diff --git a/dataengines/rememberthemilk/taskssource.h b/dataengines/rememberthemilk/taskssource.h
index 8f85f08..92cd5b9 100644
--- a/dataengines/rememberthemilk/taskssource.h
+++ b/dataengines/rememberthemilk/taskssource.h
@@ -54,6 +54,7 @@ public slots:
private slots:
void taskChanged(RTM::Task* task);
void tasksChanged();
+ void loadCache();
private:
RtmEngine *m_engine;
diff --git a/libs/rtm/request.cpp b/libs/rtm/request.cpp
index 05efe4b..7ac735a 100644
--- a/libs/rtm/request.cpp
+++ b/libs/rtm/request.cpp
@@ -50,13 +50,19 @@ void RTM::Request::addArgument(const QString &name, const QString &value) {
void RTM::Request::sendRequest()
{
static QDateTime lastRequest;
-
+ static unsigned int queueSize;
+
+ int margin = lastRequest.msecsTo(QDateTime::currentDateTime());
+
// Follow RTM's TOS and only do 1 request per second.
- if (lastRequest.secsTo(QDateTime::currentDateTime()) <= 1) {
- QTimer::singleShot(1000, this, SLOT(sendRequest()));
- //kDebug() << "Postponing Job for 1 second";
+ if (margin <= 1000) {
+ const int timeout = 1000 * (queueSize + 1) - margin + queueSize * 2 + 1;
+ QTimer::singleShot(timeout, this, SLOT(sendRequest()));
+ //kDebug() << "Postponing Job for"<<timeout<<"ms";
+ ++queueSize;
return;
}
+ queueSize = 0;
QString url = requestUrl();
kDebug() << "Request ready. Url is: " << url;
currentJob = KIO::get(KUrl(url.toUtf8()), KIO::NoReload, KIO::HideProgressInfo);
diff --git a/libs/rtm/session_p.h b/libs/rtm/session_p.h
index ab210a5..8ffedcf 100644
--- a/libs/rtm/session_p.h
+++ b/libs/rtm/session_p.h
@@ -66,25 +66,24 @@ class RTM::SessionPrivate {
void networkStatusChanged(Solid::Networking::Status status) {
switch (status) {
- case Solid::Networking::Connected: case Solid::Networking::Unknown:
+ case Solid::Networking::Connected:
+ case Solid::Networking::Unknown:
if (online)
return;
online = true;
q->checkToken();
refreshSettings();
- q->refreshListsFromServer();
- q->refreshTasksFromServer();
break;
- case Solid::Networking::Unconnected:
- case Solid::Networking::Disconnecting:
- case Solid::Networking::Connecting:
+ case Solid::Networking::Unconnected:
+ case Solid::Networking::Disconnecting:
+ case Solid::Networking::Connecting:
if (!online)
return;
online = false;
break;
- }
+ }
}
void offlineError() {
@@ -252,7 +251,7 @@ class RTM::SessionPrivate {
QObject::connect(settingsRequest, SIGNAL(replyReceived(RTM::Request*)), q, SLOT(settingsReply(RTM::Request*)));
settingsRequest->sendRequest();
}
-
+
friend class TasksReader;
friend class Session;