Help with a review of my first code using actix-web and sqlx

Hi,

I have made one example of using actix-web and sqlx in simple ToDo REST API. I have got this kind of comment:

"The todo-api example ( having just skimmed it over ) is fairly inefficient. It's doing pretty big allocation dozens and dozens of times for the /todos route."

The comment wasn't with bad intention, but it is without details that I could use to learn how to do it better/properly/efficiently.

I wish to learn Rust especially to build REST API's using actix-web and sqlx. I learning it in my free time, so it goes slow but not bad... I have a lot of experience in building web applications but mostly in script languages...

If anyone could help me with some points on places that should be done differently so I can go and learn how to do it more efficiently, that would be awesome.

Thanks in advance.

Regarding the /todos route, the challenge appears to be that you are dumping the entire database, and in doing so, loading all of the content into memory first.

As I see it, solutions here should more or less be to not dump the entire database in a single request.

1 Like

@alice thanks a lot for the feedback... this is actually awesome, I thought that it is something more related to Rust/Actix-web/SQLx.

Dumping entire database is something that should not go like that anyway, this was just my first code where I was struggle to make it working in first place and didn't think too much about features like pagination and similar...

But if all issue with my code is dumping whole database it is easy to solve. Is there maybe something related to Rust/Actix-web/SQLx?

Thanks again.

Maybe you could do something to stream the data as it arrives from the database, but I think a better design is to not have an endpoint that returns all of the data at all.

@alice yes I can agree with your idea, but it is kind of application design decisions, but what was bothering me more was my Rust/Actix-web/SQLx decisions and implementation.

Again, thanks a lot for helping me to understand that and actually it unblock me (mentally) to continue with my Rust journey.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.