Use `diesel-async` database pools
This PR moves our codebase from deadpool database pools to deadpool database pools... essentially... well... it's complicated.
The codebase currently uses the database pools from deadpool_diesel. These database pools are async, but they still return a sync database connection that can be used with regular diesel queries. With this PR we are migrating to using database pools from diesel-async in their deadpool variant. These are returning an async connection, which can be wrapped in an AsyncConnectionWrapper to make them work with sync diesel queries (in combination with spawn_blocking()).
In other words: this is just an intermediate step that allows us to use async diesel queries (enabled by diesel-async), but a lot of the code is still using sync queries with the wrapper. I've started to port over some of the simpler endpoints to use async queries, but that migration is far from complete. It should however serve as a starting point to demonstrate the end goal of removing all the spawn_blocking() calls.
Note that I had to introduce a Conn trait to abstract over the PgConnection and AsyncConnectionWrapper structs. Both implement LoadConnection<Backend = Pg>, but since trait aliases are not stabilized yet and I didn't want to repeat that signature everywhere I decided to extract the Conn trait. After that I essentially searched for &mut PgConnection and replaced it with &mut impl Conn, which is equivalent, but also allows us to pass in AsyncConnectionWrapper instead.
I would recommend reviewing this commit-by-commit... 😅
Codecov Report
Attention: Patch coverage is 93.31797% with 29 lines in your changes missing coverage. Please review.
Project coverage is 89.17%. Comparing base (
5b6cca9) to head (4795d51).
Additional details and impacted files
@@ Coverage Diff @@
## main #9161 +/- ##
==========================================
- Coverage 89.17% 89.17% -0.01%
==========================================
Files 282 282
Lines 28534 28583 +49
==========================================
+ Hits 25445 25488 +43
- Misses 3089 3095 +6
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
In other words: this is just an intermediate step that allows us to use async
dieselqueries (enabled bydiesel-async), but a lot of the code is still using sync queries with the wrapper. I've started to port over some of the simpler endpoints to use async queries, but that migration is far from complete. It should however serve as a starting point to demonstrate the end goal of removing all thespawn_blocking()calls.
I also see that there's still a lot of work to do for the migration, especially for all the models.
Let me know if you need more help.
yeah, it's far from finished but seemed like a good first step in hopefully the right direction. I haven't found a good way yet to incrementally migrate the rest of the code. Feel free to take a look while I'm on vacation :)
:umbrella: The latest upstream changes (presumably 0d4928b04b62cb0a1ca4dc9ffd206903c8b4c112) made this pull request unmergeable. Please resolve the merge conflicts.