Using mutex.
This commit is contained in:
parent
3df6c9d091
commit
8499b3f9d1
|
@ -28,7 +28,7 @@ const RATE_LIMIT_PER_SECOND: i32 = 60;
|
|||
|
||||
pub struct State {
|
||||
rate_limits: Mutex<HashMap<String, RateLimitBucket>>,
|
||||
pool: r2d2::Pool<SqliteConnectionManager>,
|
||||
pool: Mutex<r2d2::Pool<SqliteConnectionManager>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -45,7 +45,7 @@ fn main() {
|
|||
|
||||
let shared_data = web::Data::new(State {
|
||||
rate_limits: Mutex::new(HashMap::new()),
|
||||
pool: pool,
|
||||
pool: Mutex::new(pool),
|
||||
});
|
||||
|
||||
HttpServer::new(move || {
|
||||
|
@ -106,7 +106,7 @@ fn search(
|
|||
.body(format!("{{\"error\": \"{}\"}}", "Empty query".to_string()));
|
||||
}
|
||||
|
||||
let conn = data.pool.get().unwrap();
|
||||
let conn = data.pool.lock().unwrap().get().unwrap();
|
||||
|
||||
match check_rate_limit_full(data, &ip, RATE_LIMIT, RATE_LIMIT_PER_SECOND) {
|
||||
Ok(_) => HttpResponse::Ok()
|
||||
|
|
Loading…
Reference in New Issue