[BE] Log interface time with DB
This commit is contained in:
parent
ecdf900299
commit
f87263d9b7
@ -2,6 +2,7 @@ use cors::Cors;
|
|||||||
use sqlx::Connection;
|
use sqlx::Connection;
|
||||||
use sqlx::MySqlConnection;
|
use sqlx::MySqlConnection;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
@ -27,7 +28,10 @@ pub async fn db() -> Result<MySqlConnection, String> {
|
|||||||
Err(_) => return Err("env DATABASE_URL not found".to_string()),
|
Err(_) => return Err("env DATABASE_URL not found".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
let conn = sqlx::MySqlConnection::connect(db_url.as_str()).await;
|
let conn = sqlx::MySqlConnection::connect(db_url.as_str()).await;
|
||||||
|
let duration = start.elapsed();
|
||||||
|
log::info!("DB connection took: {:?} ms", duration.as_millis());
|
||||||
|
|
||||||
match conn {
|
match conn {
|
||||||
Ok(connection) => Ok(connection),
|
Ok(connection) => Ok(connection),
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
time::Instant,
|
||||||
|
};
|
||||||
|
|
||||||
use rocket::form::validate::Contains;
|
use rocket::form::validate::Contains;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -249,7 +252,15 @@ impl RegisterCreate {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut db = db().await?;
|
let mut db = db().await?;
|
||||||
match db.fetch_all(sql.as_str()).await {
|
|
||||||
|
let start = Instant::now();
|
||||||
|
let result = db.fetch_all(sql.as_str()).await;
|
||||||
|
log::info!(
|
||||||
|
"DB query (batch create) took: {:?} ms",
|
||||||
|
start.elapsed().as_millis()
|
||||||
|
);
|
||||||
|
|
||||||
|
match result {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("Error fetching course & person: {:?}", err);
|
log::error!("Error fetching course & person: {:?}", err);
|
||||||
|
Loading…
Reference in New Issue
Block a user