修改了SledDB代码,使得打开更优雅,性能更快
This commit is contained in:
1 parent
9fda014ce6
commit
a2510dc4af
6 files changed
+98
-4
No files matched your search
@@ -0,0 +1,44 @@
|
||||
use chrono::Datelike;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
pub struct UserState {
|
||||
pub is_checkin_today: bool,
|
||||
pub checkin_unix_second: u64,
|
||||
pub checkin_times_in_month: usize,
|
||||
pub checkin_days: Vec<u32>, //每月在哪天签到了
|
||||
}
|
||||
|
||||
/*
|
||||
key:用户id
|
||||
value:UserState的json字符串
|
||||
|
||||
|
||||
*/
|
||||
|
||||
impl UserState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
is_checkin_today: false,
|
||||
checkin_unix_second: 0,
|
||||
checkin_times_in_month: 0,
|
||||
checkin_days: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn checkin(&mut self) {
|
||||
self.is_checkin_today = true;
|
||||
let unix_time = tokio::time::Instant::now().elapsed().as_secs();
|
||||
|
||||
self.checkin_unix_second = unix_time;
|
||||
self.checkin_times_in_month += 1;
|
||||
let day = chrono::Utc::now().day();
|
||||
if !self.checkin_days.contains(&day) {
|
||||
self.checkin_days.push(day);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_daily(&mut self) {
|
||||
self.is_checkin_today = false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user