Compare commits

...

2 Commits

Author SHA1 Message Date
f2a3e836a0 spelling and clippy 2025-03-18 15:08:29 -06:00
3b4e6a40ce minimize vec resizing 2025-03-18 15:07:50 -06:00
2 changed files with 10 additions and 13 deletions

View File

@ -98,7 +98,7 @@ impl Website {
.await .await
.expect("Failed to check surreal for duplicates!"); .expect("Failed to check surreal for duplicates!");
if let Some(old) = response.take::<Option<Website>>(0).expect("Failed to read reponse from surreal for duplicates.") { if let Some(old) = response.take::<Option<Website>>(0).expect("Failed to read response from surreal for duplicates.") {
// site exists already // site exists already
if let Some(id) = old.id { if let Some(id) = old.id {
// make sure to preserve the "crawled status" // make sure to preserve the "crawled status"
@ -119,7 +119,7 @@ impl Website {
match error { match error {
Db::QueryCancelled => todo!(), Db::QueryCancelled => todo!(),
Db::QueryNotExecuted => todo!(), Db::QueryNotExecuted => todo!(),
Db::QueryNotExecutedDetail { message } => todo!(), Db::QueryNotExecutedDetail { message: _ } => todo!(),
_=>{}, _=>{},
} }
}, },

View File

@ -71,7 +71,7 @@ pub async fn parse(db: &Surreal<Client>, site: &mut Website, data: &str) {
site.store(db).await; site.store(db).await;
// prep work // prep work
let mut other_sites = Vec::new(); let mut other_sites: Vec<Website> = Vec::new();
{ // using blocks to prevent compiler's async worries { // using blocks to prevent compiler's async worries
let _t = Timer::start("Parsed page"); let _t = Timer::start("Parsed page");
@ -84,8 +84,9 @@ pub async fn parse(db: &Surreal<Client>, site: &mut Website, data: &str) {
let tokenizer = Tokenizer::new(site.clone(), TokenizerOpts::default()); let tokenizer = Tokenizer::new(site.clone(), TokenizerOpts::default());
// go thru buffer // go thru buffer
while let TokenizerResult::Script(sites) = tokenizer.feed(&mut token_buffer) { while let TokenizerResult::Script(mut sites) = tokenizer.feed(&mut token_buffer) {
other_sites.push(sites); other_sites.append(&mut sites);
// other_sites.push(sites);
} }
assert!(token_buffer.is_empty()); assert!(token_buffer.is_empty());
@ -93,18 +94,14 @@ pub async fn parse(db: &Surreal<Client>, site: &mut Website, data: &str) {
} }
{ {
let mut links_to = Vec::new(); let mut links_to = Vec::with_capacity(other_sites.len());
// this is a 2d vec accidentally
for a in other_sites { for a in other_sites {
for b in a { let other = a.store(db).await;
// TODO this can become a JoinSet later
let other = b.store(db).await;
if let Some(o) = other { if let Some(o) = other {
links_to.push(o); links_to.push(o);
} }
} }
}
site.links_to(links_to, db).await; site.links_to(links_to, db).await;
} }