Commit 6508fcfd authored by Alexey Chernov's avatar Alexey Chernov

Speedup of Remember The Milk dataengine and library

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.
parent d5553632
......@@ -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"
......@@ -48,6 +48,7 @@ public slots:
private slots:
void listsChanged();
void listChanged(RTM::List*);
void loadCache();
private:
RtmEngine *m_engine;
......
......@@ -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");
}
......
......@@ -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"
......@@ -54,6 +54,7 @@ public slots:
private slots:
void taskChanged(RTM::Task* task);
void tasksChanged();
void loadCache();
private:
RtmEngine *m_engine;
......
......@@ -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);
......
......@@ -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;
......
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