Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added initial version of search APIs #25

Merged
merged 10 commits into from
Apr 5, 2024
Merged

added initial version of search APIs #25

merged 10 commits into from
Apr 5, 2024

Conversation

rathijitpapon
Copy link
Member

No description provided.

Copy link
Contributor

@ivarflakstad ivarflakstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good job, @rathijitpapon ! 🙌

A couple of comments here and there, but there are only 3 things I want to see before we merge:

  1. user id foreign key in the new table and mock the user id.
  2. send real http request to our fastapi backend (while we do not have gRPC solved).
  3. A couple of tests

Comment on lines 25 to 26
services::insert_search_history(&pool, &mut connection, &search_query, &search_response)
.await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the performance characteristics of the two insertions (cache and pg). They are both async, so it shouldn't be a problem, but if we see something in the future this could be a good candidate for the spawn_blocking_with_tracing util in telemetry.rs.

Comment on lines +49 to +56
cache
.set(
&search_query.query,
serde_json::to_string(&search_response)
.map_err(|_| eyre!("unable to convert string to json"))?,
)
.await
.map_err(|e| AppError::from(e))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice!
We'll find an approach to do this as simple as cache.set(key, value).await? later 👌

Comment on lines +100 to +107
cache
.zremrangebyrank(
"search_history",
0,
-SETTINGS.cache_max_sorted_size as isize - 1,
)
.await
.map_err(|e| AppError::from(e))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this removes history with rank between (0, negative max sorted size], correct?
What is the purpose of doing that? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. It's used to remove all the unnecessary search queries from the sorted set. This way we can use smaller storage for this.

@rathijitpapon rathijitpapon merged commit 305041d into main Apr 5, 2024
1 check passed
@rathijitpapon rathijitpapon deleted the search_endpoint branch April 5, 2024 14:05
@rathijitpapon rathijitpapon restored the search_endpoint branch April 8, 2024 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants