Commit c8edb155 authored by David Jarvie's avatar David Jarvie
Browse files

Don't duplicate calculation of next trigger time of alarms

Calculating the next trigger time can sometimes be processor
intensive.
parent 98321fdb
Pipeline #35584 passed with stage
in 13 minutes and 46 seconds
......@@ -844,10 +844,10 @@ void KAlarmApp::checkNextDueAlarm()
if (!mAlarmsEnabled)
return;
// Find the first alarm due
const KAEvent nextEvent = ResourcesCalendar::earliestAlarm();
KADateTime nextDt;
const KAEvent nextEvent = ResourcesCalendar::earliestAlarm(nextDt);
if (!nextEvent.isValid())
return; // there are no alarms pending
const KADateTime nextDt = nextEvent.nextTrigger(KAEvent::ALL_TRIGGER).effectiveKDateTime();
const KADateTime now = KADateTime::currentDateTime(Preferences::timeSpec());
qint64 interval = now.msecsTo(nextDt);
qCDebug(KALARM_LOG) << "KAlarmApp::checkNextDueAlarm: now:" << qPrintable(now.toString(QStringLiteral("%Y-%m-%d %H:%M %:Z"))) << ", next:" << qPrintable(nextDt.toString(QStringLiteral("%Y-%m-%d %H:%M %:Z"))) << ", due:" << interval;
......
......@@ -647,7 +647,7 @@ void ResourcesCalendar::findEarliestAlarm(const Resource& resource)
* Return the active alarm with the earliest trigger time.
* Reply = invalid if none.
*/
KAEvent ResourcesCalendar::earliestAlarm()
KAEvent ResourcesCalendar::earliestAlarm(KADateTime& nextTriggerTime)
{
KAEvent earliest;
KADateTime earliestTime;
......@@ -663,7 +663,7 @@ KAEvent ResourcesCalendar::earliestAlarm()
// Something went wrong: mEarliestAlarm wasn't updated when it should have been!!
qCCritical(KALARM_LOG) << "ResourcesCalendar::earliestAlarm: resource" << eit.key() << "does not contain" << id;
mInstance->findEarliestAlarm(res);
return earliestAlarm();
return earliestAlarm(nextTriggerTime);
}
const KADateTime dt = event.nextTrigger(KAEvent::ALL_TRIGGER).effectiveKDateTime();
if (dt.isValid() && (!earliest.isValid() || dt < earliestTime))
......@@ -672,6 +672,7 @@ KAEvent ResourcesCalendar::earliestAlarm()
earliest = event;
}
}
nextTriggerTime = earliestTime;
return earliest;
}
......
......@@ -36,7 +36,13 @@ public:
~ResourcesCalendar() override;
static void initialise(const QByteArray& appName, const QByteArray& appVersion);
static void terminate();
static KAEvent earliestAlarm();
/** Return the active alarm with the earliest trigger time.
* @param nextTriggerTime The next trigger time of the earliest alarm.
* @return The earliest alarm.
*/
static KAEvent earliestAlarm(KADateTime& nextTriggerTime);
static void setAlarmPending(const KAEvent&, bool pending = true);
static bool haveDisabledAlarms() { return mHaveDisabledAlarms; }
static void disabledChanged(const KAEvent&);
......
......@@ -261,11 +261,11 @@ void TrayWindow::updateStatus()
active = theApp()->alarmsEnabled();
if (active)
{
const KAEvent& event = ResourcesCalendar::earliestAlarm();
KADateTime dt;
const KAEvent& event = ResourcesCalendar::earliestAlarm(dt);
active = event.isValid();
if (active && period > 0)
{
const KADateTime dt = event.nextTrigger(KAEvent::ALL_TRIGGER).effectiveKDateTime();
qint64 delay = KADateTime::currentLocalDateTime().secsTo(dt);
delay -= static_cast<qint64>(period) * 60; // delay until icon to be shown
active = (delay <= 0);
......
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