update levels in cache when db is updated

This commit is contained in:
realaravinth 2021-08-31 13:54:05 +05:30
parent b1fd56e9b6
commit f7afc72d81
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 19 additions and 17 deletions

View file

@ -17,7 +17,7 @@
use actix_identity::Identity;
use actix_web::{web, HttpResponse, Responder};
use futures::future::try_join_all;
use libmcaptcha::{defense::Level, DefenseBuilder};
use libmcaptcha::{defense::Level, DefenseBuilder, master::messages::RemoveCaptcha};
use log::debug;
use serde::{Deserialize, Serialize};
@ -190,6 +190,9 @@ async fn update_levels(
}
try_join_all(futs).await?;
if let Err(ServiceError::CaptchaError(e)) = data.captcha.remove(RemoveCaptcha(payload.key.clone())).await {
log::error!("Deleting captcha key {} while updating it, error: {:?}", &payload.key, e)
}
Ok(HttpResponse::Ok())
}
@ -277,7 +280,6 @@ mod tests {
let app = get_app!(data).await;
// 2. get level
let add_level = get_level_data();
let get_level_resp = test::call_service(
&app,

View file

@ -1,19 +1,19 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::env;
use lazy_static::lazy_static;