only update last_seen every 12 hours
This commit is contained in:
parent
ac0af7970d
commit
8c666c3f78
1 changed files with 16 additions and 2 deletions
18
src/users.rs
18
src/users.rs
|
@ -1,4 +1,7 @@
|
|||
use std::fmt::Display;
|
||||
use std::{
|
||||
fmt::Display,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use axum::{extract::State, http::Request, middleware::Next, response::IntoResponse};
|
||||
use axum_login::{secrecy::SecretVec, AuthUser};
|
||||
|
@ -78,7 +81,18 @@ pub async fn handle_update_last_seen<BodyT>(
|
|||
next: Next<BodyT>,
|
||||
) -> impl IntoResponse {
|
||||
if let Some(user) = auth.current_user {
|
||||
user.update_last_seen(&pool).await;
|
||||
if let Some(then) = user.last_seen {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs() as i64;
|
||||
// The Nyquist frequency for 1-day tracking resolution is 12 hours.
|
||||
if now - then > 12 * 3600 {
|
||||
user.update_last_seen(&pool).await;
|
||||
}
|
||||
} else {
|
||||
user.update_last_seen(&pool).await;
|
||||
}
|
||||
}
|
||||
next.run(request).await
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue