From kde-commits Sun May 31 22:28:26 2015 From: =?utf-8?b?SXZhbiDEjHVracSH?= Date: Sun, 31 May 2015 22:28:26 +0000 To: kde-commits Subject: [kactivities] /: Removing old events from the database periodically Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=143311132002198 Git commit a400d99c393eba22033b75d6d29a7dac608586a6 by Ivan =C4=8Cuki=C4=87. Committed on 31/05/2015 at 21:42. Pushed by ivan into branch 'master'. Removing old events from the database periodically M +1 -4 TODO M +12 -4 src/service/plugins/sqlite/StatsPlugin.cpp M +5 -0 src/service/plugins/sqlite/StatsPlugin.h http://commits.kde.org/kactivities/a400d99c393eba22033b75d6d29a7dac608586a6 diff --git a/TODO b/TODO index 6bba032..c4c8f18 100644 --- a/TODO +++ b/TODO @@ -46,10 +46,7 @@ src/service/ksmserver/KSMServer.cpp:72: In future, the session management for Wayland may also need to be reimplemented in some way. = -src/service/plugins/sqlite/StatsPlugin.cpp:117: - TODO: Event cleanup should be also done from time to time, - not only on startup -src/service/plugins/sqlite/StatsPlugin.cpp:408: +src/service/plugins/sqlite/StatsPlugin.cpp:414: TODO: Add focus and modification = src/service/Application.cpp:155: diff --git a/src/service/plugins/sqlite/StatsPlugin.cpp b/src/service/plugi= ns/sqlite/StatsPlugin.cpp index 6cd5dad..28cbeb2 100644 --- a/src/service/plugins/sqlite/StatsPlugin.cpp +++ b/src/service/plugins/sqlite/StatsPlugin.cpp @@ -113,10 +113,13 @@ void StatsPlugin::loadConfiguration() m_apps.insert(apps.cbegin(), apps.cend()); } = - // Delete old events, as per configuration - // TODO: Event cleanup should be also done from time to time, - // not only on startup - DeleteEarlierStats(QString(), config().readEntry("keep-history-for", 0= )); + // Delete old events, as per configuration. + // For people who do not restart their computers, we should do this fr= om + // time to time. Doing this twice a day should be more than enough. + deleteOldEvents(); + m_deleteOldEventsTimer.setInterval(12 * 60 * 60 * 1000); + connect(&m_deleteOldEventsTimer, &QTimer::timeout, + this, &StatsPlugin::deleteOldEvents); = // Loading URL filters m_urlFilters.clear(); @@ -133,6 +136,11 @@ void StatsPlugin::loadConfiguration() } } = +void StatsPlugin::deleteOldEvents() +{ + DeleteEarlierStats(QString(), config().readEntry("keep-history-for", 0= )); +} + void StatsPlugin::openResourceEvent(const QString &usedActivity, const QString &initiatingAgent, const QString &targettedResource, diff --git a/src/service/plugins/sqlite/StatsPlugin.h b/src/service/plugins= /sqlite/StatsPlugin.h index 539660a..8e4f17a 100644 --- a/src/service/plugins/sqlite/StatsPlugin.h +++ b/src/service/plugins/sqlite/StatsPlugin.h @@ -20,6 +20,7 @@ = // Qt #include +#include = // Boost and STL #include @@ -109,6 +110,8 @@ private Q_SLOTS: bool insertResourceInfo(const QString &uri); void detectResourceInfo(const QString &uri); = + void deleteOldEvents(); + private: inline bool acceptedEvent(const Event &event); inline Event validateEvent(Event event); @@ -133,6 +136,8 @@ private: std::unique_ptr saveResourceTitleQuery; std::unique_ptr saveResourceMimetypeQuery; = + QTimer m_deleteOldEventsTimer; + bool m_blockedByDefault : 1; bool m_blockAll : 1; WhatToRemember m_whatToRemember : 2;