fix: proper fix for teh dissapearing id_wolves
This commit is contained in:
parent
93481029a6
commit
3d882056bc
1 changed files with 27 additions and 8 deletions
|
@ -56,9 +56,7 @@ async fn update_wolves_id(db: &Pool<Sqlite>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_account_hashmap(db: &Pool<Sqlite>) -> HashMap<String, Accounts> {
|
async fn get_account(db: &Pool<Sqlite>) -> Vec<Accounts> {
|
||||||
// get all users, toss in hashmap then query for differences?
|
|
||||||
let mut users_existing = HashMap::new();
|
|
||||||
match sqlx::query_as::<_, Accounts>(
|
match sqlx::query_as::<_, Accounts>(
|
||||||
r#"
|
r#"
|
||||||
SELECT *
|
SELECT *
|
||||||
|
@ -69,15 +67,28 @@ async fn get_account_hashmap(db: &Pool<Sqlite>) -> HashMap<String, Accounts> {
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
for account in &res {
|
return res;
|
||||||
users_existing.insert(account.user.to_owned(), account.to_owned());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
dbg!(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
|
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
|
// use this to pre load a large chunk of data
|
||||||
if let Ok(x) = ldap.search(
|
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() {
|
if tmp.attrs.contains_key("uidNumber") && !tmp.attrs["uidNumber"].is_empty() {
|
||||||
tmp_account.uid = tmp.attrs["uidNumber"][0].clone().parse().unwrap_or(0);
|
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() {
|
if tmp.attrs.contains_key("mail") && !tmp.attrs["mail"].is_empty() {
|
||||||
tmp_account.mail = tmp.attrs["mail"][0].clone();
|
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() {
|
if tmp.attrs.contains_key("skID") && !tmp.attrs["skID"].is_empty() {
|
||||||
tmp_account.student_id = tmp.attrs["skID"][0].clone();
|
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() {
|
if !tmp_account.user.is_empty() {
|
||||||
match existing_accounts.get(&tmp_account.user) {
|
match existing_accounts_username.get(&tmp_account.user) {
|
||||||
None => {
|
None => {
|
||||||
update_accounts(&mut transaction, &tmp_account).await;
|
update_accounts(&mut transaction, &tmp_account).await;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue