File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,11 +15,12 @@ async fn main() -> Result<(), Error> {
1515 // Share database connection between executions.
1616 // This prevents each lambda invocation from creating a new connection to
1717 // the database.
18- let database = dailp:: Database :: connect ( ) . await ?;
18+ let connections = Some ( 16 ) ;
19+ let database = dailp:: Database :: connect ( connections) . await ?;
1920 let schema = {
2021 Schema :: build ( Query , Mutation , EmptySubscription )
2122 . data ( DataLoader :: new (
22- dailp:: Database :: connect ( ) . await ?,
23+ dailp:: Database :: connect ( connections ) . await ?,
2324 tokio:: spawn,
2425 ) )
2526 . finish ( )
Original file line number Diff line number Diff line change @@ -24,14 +24,14 @@ async fn main() -> tide::Result<()> {
2424 // create schema
2525 let schema = Schema :: build ( query:: Query , query:: Mutation , EmptySubscription )
2626 . data ( DataLoader :: new (
27- dailp:: Database :: connect ( ) . await ?,
27+ dailp:: Database :: connect ( None ) . await ?,
2828 tokio:: spawn,
2929 ) )
3030 . finish ( ) ;
3131
3232 let authed_schema = Schema :: build ( query:: Query , query:: Mutation , EmptySubscription )
3333 . data ( DataLoader :: new (
34- dailp:: Database :: connect ( ) . await ?,
34+ dailp:: Database :: connect ( None ) . await ?,
3535 tokio:: spawn,
3636 ) )
3737 . data ( UserInfo :: new_test_admin ( ) )
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ async fn main() -> Result<()> {
2727 println ! ( "Validating manuscript spreadsheets..." ) ;
2828 validate_documents ( ) . await ?;
2929
30- let db = Database :: connect ( ) . await ?;
30+ let db = Database :: connect ( Some ( 1 ) ) . await ?;
3131
3232 println ! ( "Migrating Image Sources..." ) ;
3333 migrate_image_sources ( & db) . await ?;
Original file line number Diff line number Diff line change @@ -26,11 +26,13 @@ pub struct Database {
2626 client : sqlx:: Pool < sqlx:: Postgres > ,
2727}
2828impl Database {
29- pub async fn connect ( ) -> Result < Self > {
29+ pub async fn connect ( num_connections : Option < u32 > ) -> Result < Self > {
3030 let db_url = std:: env:: var ( "DATABASE_URL" ) ?;
3131 let conn = PgPoolOptions :: new ( )
32- . max_connections ( std:: thread:: available_parallelism ( ) . map_or ( 2 , |x| x. get ( ) as u32 ) )
33- . acquire_timeout ( Duration :: from_secs ( 60 * 4 ) )
32+ . max_connections ( num_connections. unwrap_or_else ( || {
33+ std:: thread:: available_parallelism ( ) . map_or ( 2 , |x| x. get ( ) as u32 )
34+ } ) )
35+ . acquire_timeout ( Duration :: from_secs ( 60 * 8 ) )
3436 // Disable excessive pings to the database.
3537 . test_before_acquire ( false )
3638 . connect ( & db_url)
You can’t perform that action at this time.
0 commit comments