generalize upsert_nip05_validity for both pass and fail cases

This commit is contained in:
Mike Dilger 2023-01-07 02:45:10 +13:00
parent d4fbce40e7
commit f094c27ca6
2 changed files with 12 additions and 7 deletions

View File

@ -592,9 +592,10 @@ impl Overlord {
.people .people
.write() .write()
.await .await
.upsert_valid_nip05( .upsert_nip05_validity(
&(*pubkey).into(), &(*pubkey).into(),
dns_id.clone(), Some(dns_id.clone()),
true,
Unixtime::now().unwrap().0 as u64, Unixtime::now().unwrap().0 as u64,
) )
.await?; .await?;

View File

@ -353,22 +353,24 @@ impl People {
Ok(()) Ok(())
} }
pub async fn upsert_valid_nip05( pub async fn upsert_nip05_validity(
&mut self, &mut self,
pubkeyhex: &PublicKeyHex, pubkeyhex: &PublicKeyHex,
dns_id: String, dns_id: Option<String>,
dns_id_valid: bool,
dns_id_last_checked: u64, dns_id_last_checked: u64,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Update memory // Update memory
if let Some(dbperson) = self.people.get_mut(pubkeyhex) { if let Some(dbperson) = self.people.get_mut(pubkeyhex) {
dbperson.dns_id = Some(dns_id.clone()); dbperson.dns_id = dns_id.clone();
dbperson.dns_id_valid = u8::from(dns_id_valid);
dbperson.dns_id_last_checked = Some(dns_id_last_checked); dbperson.dns_id_last_checked = Some(dns_id_last_checked);
} }
// Update in database // Update in database
let sql = "INSERT INTO person (pubkey, dns_id, dns_id_valid, dns_id_last_checked) \ let sql = "INSERT INTO person (pubkey, dns_id, dns_id_valid, dns_id_last_checked) \
values (?, ?, 1, ?) \ values (?, ?, ?, ?) \
ON CONFLICT(pubkey) DO UPDATE SET dns_id=?, dns_id_valid=1, dns_id_last_checked=?"; ON CONFLICT(pubkey) DO UPDATE SET dns_id=?, dns_id_valid=?, dns_id_last_checked=?";
let pubkeyhex2 = pubkeyhex.to_owned(); let pubkeyhex2 = pubkeyhex.to_owned();
task::spawn_blocking(move || { task::spawn_blocking(move || {
@ -379,8 +381,10 @@ impl People {
stmt.execute(( stmt.execute((
&pubkeyhex2.0, &pubkeyhex2.0,
&dns_id, &dns_id,
&dns_id_valid,
&dns_id_last_checked, &dns_id_last_checked,
&dns_id, &dns_id,
&dns_id_valid,
&dns_id_last_checked, &dns_id_last_checked,
))?; ))?;
Ok::<(), Error>(()) Ok::<(), Error>(())