Skip to content

Commit

Permalink
Improve search speed (#47)
Browse files Browse the repository at this point in the history
* workspace improvements

* Improve search speed
  • Loading branch information
andy-t-wang authored Dec 31, 2024
1 parent 0babd0b commit df171e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a",
"cSpell.words": [
"sqlx"
]
}
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a",
"cSpell.words": ["sqlx"],
"editor.formatOnSave": true,
"rust-analyzer.check.command": "clippy"
}
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
components = ["rustfmt", "clippy"] # Additional tools to install
11 changes: 6 additions & 5 deletions src/routes/api/v1/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ pub async fn search(
let names = sqlx::query_as!(
Name,
"SELECT * FROM names
WHERE username % $1
ORDER BY username <-> $1
LIMIT 10;",
WHERE username % $1
AND similarity(username, $1) > 0.4
ORDER BY username <-> $1
LIMIT 10;",
lowercase_username
)
.fetch_all(&db.read_only)
.await?;

return Ok(Json(
Ok(Json(
names
.into_iter()
.map(UsernameRecord::from)
.collect::<Vec<UsernameRecord>>(),
)
.into_response());
.into_response())
}

pub fn docs(op: aide::transform::TransformOperation) -> aide::transform::TransformOperation {
Expand Down

0 comments on commit df171e5

Please sign in to comment.