mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 00:59:07 -05:00
perf: separate out blob and string tag queries
This commit is contained in:
parent
2d3a35fe30
commit
1820e9c689
|
@ -800,6 +800,34 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec<Box<dyn ToSql>>, Option<Stri
|
||||||
str_vals.push(Box::new(v.clone()));
|
str_vals.push(Box::new(v.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// do not mix value and value_hex; this is a temporary special case.
|
||||||
|
if str_vals.len() == 0 {
|
||||||
|
// create clauses with "?" params for each tag value being searched
|
||||||
|
let blob_clause = format!("value_hex IN ({})", repeat_vars(blob_vals.len()));
|
||||||
|
// find evidence of the target tag name/value existing for this event.
|
||||||
|
let tag_clause = format!(
|
||||||
|
"e.id IN (SELECT e.id FROM event e LEFT JOIN tag t on e.id=t.event_id WHERE hidden!=TRUE and (name=? AND {}))",
|
||||||
|
blob_clause
|
||||||
|
);
|
||||||
|
// add the tag name as the first parameter
|
||||||
|
params.push(Box::new(key.to_string()));
|
||||||
|
// add all tag values that are blobs as params
|
||||||
|
params.append(&mut blob_vals);
|
||||||
|
filter_components.push(tag_clause);
|
||||||
|
} else if blob_vals.len() == 0 {
|
||||||
|
// create clauses with "?" params for each tag value being searched
|
||||||
|
let str_clause = format!("value IN ({})", repeat_vars(str_vals.len()));
|
||||||
|
// find evidence of the target tag name/value existing for this event.
|
||||||
|
let tag_clause = format!(
|
||||||
|
"e.id IN (SELECT e.id FROM event e LEFT JOIN tag t on e.id=t.event_id WHERE hidden!=TRUE and (name=? AND {}))",
|
||||||
|
str_clause
|
||||||
|
);
|
||||||
|
// add the tag name as the first parameter
|
||||||
|
params.push(Box::new(key.to_string()));
|
||||||
|
// add all tag values that are blobs as params
|
||||||
|
params.append(&mut str_vals);
|
||||||
|
filter_components.push(tag_clause);
|
||||||
|
} else {
|
||||||
// create clauses with "?" params for each tag value being searched
|
// create clauses with "?" params for each tag value being searched
|
||||||
let str_clause = format!("value IN ({})", repeat_vars(str_vals.len()));
|
let str_clause = format!("value IN ({})", repeat_vars(str_vals.len()));
|
||||||
let blob_clause = format!("value_hex IN ({})", repeat_vars(blob_vals.len()));
|
let blob_clause = format!("value_hex IN ({})", repeat_vars(blob_vals.len()));
|
||||||
|
@ -817,6 +845,7 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec<Box<dyn ToSql>>, Option<Stri
|
||||||
filter_components.push(tag_clause);
|
filter_components.push(tag_clause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Query for timestamp
|
// Query for timestamp
|
||||||
if f.since.is_some() {
|
if f.since.is_some() {
|
||||||
let created_clause = format!("created_at > {}", f.since.unwrap());
|
let created_clause = format!("created_at > {}", f.since.unwrap());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user