db-lib::Member::Update no longer does 2 network hits
Also is a lot more straight forward to use as it basically return Response::Success and Other in case of issue Member::update_perms now a thing which is again pasted from previously working code and uses Result<_, _> return types so we can ? everywhere $ Using ? is basically a try so latency should be reduced in this method
This commit is contained in:
parent
7c41db0648
commit
56041c1da5
@ -64,33 +64,22 @@ impl FromDB<Member, Integer> for Member {
|
||||
let q = r#"UPDATE members
|
||||
SET status = :status, permissions = :perms, name = :name
|
||||
WHERE id = :id"#;
|
||||
// TODO: remoev this retarded extra network hit
|
||||
// technically this is really nice for the user but ultimately it either works or it
|
||||
// doesn't so like the fucks the point of doing some bs like this
|
||||
// the next a client queries this they'll get whatever data is in the db
|
||||
// likewise clients are going likely going to re-get this data since its been updated
|
||||
// or at least should
|
||||
|
||||
if let Ok(conn) = p.get_conn().await {
|
||||
match Member::get(p, row.id).await {
|
||||
Response::Row(_) => {
|
||||
let db_result: Result<Conn, SqlError>
|
||||
= conn.drop_exec(q, params!{
|
||||
"id" => row.id,
|
||||
"status" => row.status,
|
||||
"name" => row.name,
|
||||
"perms" => row.permissions
|
||||
}).await;
|
||||
match db_result {
|
||||
Ok(_) => return Response::Success,
|
||||
Err(_) => return Response::Other(sql_err!("WARN member found | Member::FromDB::update failed - "))
|
||||
}
|
||||
},
|
||||
Response::Empty => return Response::Empty,
|
||||
Response::Other(msg) => return Response::Other(msg),
|
||||
_ => return Response::Other(sql_err!("Member::FromD::update Bro i dont even"))
|
||||
let query = conn.drop_exec(q, params!{
|
||||
"id" => row.id,
|
||||
"status" => row.status,
|
||||
"name" => row.name,
|
||||
"perms" => row.permissions
|
||||
}).await;
|
||||
|
||||
return match query {
|
||||
Ok(_) => Response::Success,
|
||||
Err(err) => Response::Other(sql_err!(err))
|
||||
}
|
||||
}
|
||||
return Response::Other(no_conn!("Member::FromDB::update"));
|
||||
|
||||
return Response::Other(no_conn!("db::Member::update"));
|
||||
}
|
||||
|
||||
async fn delete(p: &Pool, id: UBigInt) -> Response<Self> {
|
||||
@ -205,4 +194,18 @@ impl Member {
|
||||
|
||||
return Ok(Response::Empty);
|
||||
}
|
||||
|
||||
pub async fn update_perms(p: &Pool, uid: UBigInt, permissions: UBigInt) -> Result<UBigInt, SqlError> {
|
||||
//! @return on_sucess Ok(NewPermisionsMask)
|
||||
//!
|
||||
let conn = p.get_conn().await?;
|
||||
conn.drop_exec(
|
||||
"UPDATE members SET permissions = :perms WHERE id = :id",
|
||||
params!{
|
||||
"id" => uid,
|
||||
"perms" => permissions
|
||||
}).await?;
|
||||
|
||||
Ok(permissions)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user