fbdaemon/fbgeneratorjob.cpp
Christian Mollekopf
mollekopf at kolabsys.com
Fri Jul 20 13:29:28 CEST 2012
fbdaemon/fbgeneratorjob.cpp | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
New commits:
commit 97bf3122a002dc2e6dbb3f061d2d19c1924d8b7e
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Jul 20 13:29:24 2012 +0200
Check timerame.
diff --git a/fbdaemon/fbgeneratorjob.cpp b/fbdaemon/fbgeneratorjob.cpp
index 2e7f774..ed731f0 100644
--- a/fbdaemon/fbgeneratorjob.cpp
+++ b/fbdaemon/fbgeneratorjob.cpp
@@ -26,6 +26,7 @@
#include <jobs/messagemodifyjob.h>
#include <jobs/fetchmessagesjob.h>
#include <jobs/sequentialcompositejob.h>
+#include <commonconversion.h>
#include <kolabdefinitions.h>
#include <kolabobject.h>
@@ -86,30 +87,55 @@ void FBGeneratorJob::onFetchFBDone(KJob *job)
kDebug() << "existing fb object " << msg->subject()->asUnicodeString();
}
+ KDateTime startOfTimeFrame = KDateTime::currentUtcDateTime();
+ const KDateTime endOfTimeFrame = startOfTimeFrame.addDays(Settings::instance().getTimeframe());
+ int threshold = Settings::instance().getThreshold();
+
/*
* The f/b object to update is identified based on a Mime-Header
*
* For the local server we're going to use the Settings::getServerUri()
*/
const QString localUri = Settings::instance().getServerUri().toUtf8();
+ int count = 0;
+ bool upToDate;
foreach (const KMime::Message::Ptr &msg, fetchJob->getMessages()) {
KMime::Headers::Base *xOriginHeader = msg->getHeaderByType(X_ORIGIN_HEADER);
if (xOriginHeader) kDebug() << "existing fb object " << xOriginHeader->asUnicodeString() << localUri;
if (xOriginHeader && (xOriginHeader->asUnicodeString() == localUri)) {
+
+ const Kolab::Freebusy &oldFB = Kolab::KolabObjectReader(msg).getFreebusy();
+ const KDateTime dtstamp = Kolab::Conversion::toDate(oldFB.timestamp());
+ const KDateTime start = Kolab::Conversion::toDate(oldFB.start());
+ const KDateTime end = Kolab::Conversion::toDate(oldFB.end());
+
+ if (!(startOfTimeFrame < start || endOfTimeFrame > end.addDays(threshold))) {
+ kDebug() << "within threshold, skipping";
+ upToDate = true;
+ continue;
+ }
- mOldImapUid = fetchJob->getImapUid(msg);
- mOldFlags = fetchJob->getFlags(msg);
- break;
+ if (mOldImapUid) {
+ mOldImapUid = fetchJob->getImapUid(msg);
+ mOldFlags = fetchJob->getFlags(msg);
+ }
+ count++;
}
}
- //TODO check timeframe of existing f/b object, maybe we don't need to regenerate
+ if (count > 1) {
+ kWarning() << "multiple old fb objects detected this shouldn't ever happen";
+ //TODO cleanup
+ }
+ if (upToDate) {
+ kDebug() << "fb objects are up-to-date, nothing to do";
+ emitResult();
+ return;
+ }
//TODO also check events if anything changed
- KDateTime start = KDateTime::currentUtcDateTime();
- KDateTime end = start.addDays(Settings::instance().getTimeframe());
// kDebug() << mEventFolder;
- GenerateFBJob *fbJob = new GenerateFBJob(mEventFolders, start, end, mSession, this);
+ GenerateFBJob *fbJob = new GenerateFBJob(mEventFolders, startOfTimeFrame, endOfTimeFrame, mSession, this);
QObject::connect(fbJob, SIGNAL(result(KJob*)), this, SLOT(onGenerateFBDone(KJob*)));
fbJob->start();
}
More information about the commits
mailing list