fix: proper fix for teh dissapearing id_wolves
All checks were successful
Build / build (push) Successful in 1m3s
Build / deploy (push) Successful in 6s

This commit is contained in:
silver 2025-09-07 18:58:35 +01:00
parent 93481029a6
commit 3d882056bc
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -56,9 +56,7 @@ async fn update_wolves_id(db: &Pool<Sqlite>) {
}
}
async fn get_account_hashmap(db: &Pool<Sqlite>) -> HashMap<String, Accounts> {
// get all users, toss in hashmap then query for differences?
let mut users_existing = HashMap::new();
async fn get_account(db: &Pool<Sqlite>) -> Vec<Accounts> {
match sqlx::query_as::<_, Accounts>(
r#"
SELECT *
@ -69,15 +67,28 @@ async fn get_account_hashmap(db: &Pool<Sqlite>) -> HashMap<String, Accounts> {
.await
{
Ok(res) => {
for account in &res {
users_existing.insert(account.user.to_owned(), account.to_owned());
}
return res;
}
Err(e) => {
dbg!(e);
}
}
vec![]
}
fn get_account_hashmap_username(accounts: &Vec<Accounts>) -> HashMap<String, Accounts> {
let mut users_existing = HashMap::new();
for account in accounts {
users_existing.insert(account.user.to_owned(), account.to_owned());
}
users_existing
}
fn get_account_hashmap_email(accounts: &Vec<Accounts>) -> HashMap<String, Accounts> {
let mut users_existing = HashMap::new();
for account in accounts {
users_existing.insert(account.mail.to_owned(), account.to_owned());
}
users_existing
}
@ -98,7 +109,10 @@ async fn update_ldap(config: &Config, db: &Pool<Sqlite>) {
}
}
let existing_accounts = get_account_hashmap(db).await;
let existing_accounts = get_account(db).await;
let existing_accounts_username = get_account_hashmap_username(&existing_accounts);
let existing_accounts_email = get_account_hashmap_email(&existing_accounts);
// use this to pre load a large chunk of data
if let Ok(x) = ldap.search(
@ -129,8 +143,13 @@ async fn update_ldap(config: &Config, db: &Pool<Sqlite>) {
if tmp.attrs.contains_key("uidNumber") && !tmp.attrs["uidNumber"].is_empty() {
tmp_account.uid = tmp.attrs["uidNumber"][0].clone().parse().unwrap_or(0);
}
// mail is what ties them together
if tmp.attrs.contains_key("mail") && !tmp.attrs["mail"].is_empty() {
tmp_account.mail = tmp.attrs["mail"][0].clone();
if let Some(x) = existing_accounts_email.get(&tmp_account.mail) {
tmp_account.student_id = x.student_id.to_owned();
tmp_account.id_wolves = x.id_wolves;
}
}
if tmp.attrs.contains_key("skID") && !tmp.attrs["skID"].is_empty() {
tmp_account.student_id = tmp.attrs["skID"][0].clone();
@ -140,7 +159,7 @@ async fn update_ldap(config: &Config, db: &Pool<Sqlite>) {
}
if !tmp_account.user.is_empty() {
match existing_accounts.get(&tmp_account.user) {
match existing_accounts_username.get(&tmp_account.user) {
None => {
update_accounts(&mut transaction, &tmp_account).await;
}