From ab6fbaca11a9f28ba9eaac8f28ebf708c56e4eee Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sat, 13 Nov 2021 09:05:16 -0800 Subject: [PATCH] Removing expired links and avatars. --- build | 2 +- src/RESTAPI/RESTAPI_user_handler.cpp | 3 +++ src/StorageService.cpp | 4 +++- src/StorageService.h | 1 + src/storage/storage_actionLinks.cpp | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/build b/build index eebd1d1..4e9e288 100644 --- a/build +++ b/build @@ -1 +1 @@ -61 \ No newline at end of file +63 \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_user_handler.cpp b/src/RESTAPI/RESTAPI_user_handler.cpp index d7e3feb..4ad92dc 100644 --- a/src/RESTAPI/RESTAPI_user_handler.cpp +++ b/src/RESTAPI/RESTAPI_user_handler.cpp @@ -57,6 +57,9 @@ namespace OpenWifi { if(AuthService()->DeleteUserFromCache(UInfo.email)) { // nothing to do } + + StorageService()->DeleteAvatar(UserInfo_.userinfo.email,Id); + Logger_.information(Poco::format("Remove all tokens for '%s'", UserInfo_.userinfo.email)); StorageService()->RevokeAllTokens(UInfo.email); Logger_.information(Poco::format("User '%s' deleted by '%s'.",Id,UserInfo_.userinfo.email)); diff --git a/src/StorageService.cpp b/src/StorageService.cpp index 548136d..9630782 100644 --- a/src/StorageService.cpp +++ b/src/StorageService.cpp @@ -33,8 +33,10 @@ namespace OpenWifi { void Archiver::onTimer(Poco::Timer &timer) { Poco::Logger &logger = Poco::Logger::get("STORAGE-ARCHIVER"); - logger.information("Squiggy the DB"); + logger.information("Squiggy the DB: removing old tokens."); StorageService()->CleanExpiredTokens(); + logger.information("Squiggy the DB: removing old actionLinks."); + StorageService()->CleanOldActionLinks(); } } diff --git a/src/StorageService.h b/src/StorageService.h index 623da91..f07436c 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -129,6 +129,7 @@ namespace OpenWifi { bool SentAction(std::string &ActionId); bool GetActionLink(std::string &ActionId, SecurityObjects::ActionLink &A); bool GetActions(std::vector &Links, uint64_t Max=200); + void CleanOldActionLinks(); private: int Create_Tables(); diff --git a/src/storage/storage_actionLinks.cpp b/src/storage/storage_actionLinks.cpp index 6ad0c09..7d0b297 100644 --- a/src/storage/storage_actionLinks.cpp +++ b/src/storage/storage_actionLinks.cpp @@ -183,4 +183,19 @@ namespace OpenWifi { return false; } + void Storage::CleanOldActionLinks() { + try { + Poco::Data::Session Sess = Pool_->get(); + Poco::Data::Statement Delete(Sess); + + uint64_t CutOff = std::time(nullptr) - (30 * 24 * 60 * 60); + std::string St{"DELETE from ActionLinks where Created<=?"}; + Delete << ConvertParams(St), + Poco::Data::Keywords::use(CutOff); + Delete.execute(); + } catch (const Poco::Exception &E) { + Logger_.log(E); + } + } + } \ No newline at end of file