@@ -110,14 +110,20 @@ impl CrateOwnerInvitation {
110110 . await
111111 }
112112
113- pub fn accept ( self , conn : & mut impl Conn , config : & config:: Server ) -> AppResult < ( ) > {
114- use diesel:: RunQueryDsl ;
113+ pub async fn accept (
114+ self ,
115+ conn : & mut AsyncPgConnection ,
116+ config : & config:: Server ,
117+ ) -> AppResult < ( ) > {
118+ use diesel_async:: scoped_futures:: ScopedFutureExt ;
119+ use diesel_async:: { AsyncConnection , RunQueryDsl } ;
115120
116121 if self . is_expired ( config) {
117122 let crate_name: String = crates:: table
118123 . find ( self . crate_id )
119124 . select ( crates:: name)
120- . first ( conn) ?;
125+ . first ( conn)
126+ . await ?;
121127
122128 let detail = format ! (
123129 "The invitation to become an owner of the {crate_name} crate expired. \
@@ -128,33 +134,38 @@ impl CrateOwnerInvitation {
128134 }
129135
130136 conn. transaction ( |conn| {
131- diesel:: insert_into ( crate_owners:: table)
132- . values ( & CrateOwner {
133- crate_id : self . crate_id ,
134- owner_id : self . invited_user_id ,
135- created_by : self . invited_by_user_id ,
136- owner_kind : OwnerKind :: User ,
137- email_notifications : true ,
138- } )
139- . on_conflict ( crate_owners:: table. primary_key ( ) )
140- . do_update ( )
141- . set ( crate_owners:: deleted. eq ( false ) )
142- . execute ( conn) ?;
143-
144- diesel:: delete ( & self ) . execute ( conn) ?;
145-
146- Ok ( ( ) )
137+ async move {
138+ diesel:: insert_into ( crate_owners:: table)
139+ . values ( & CrateOwner {
140+ crate_id : self . crate_id ,
141+ owner_id : self . invited_user_id ,
142+ created_by : self . invited_by_user_id ,
143+ owner_kind : OwnerKind :: User ,
144+ email_notifications : true ,
145+ } )
146+ . on_conflict ( crate_owners:: table. primary_key ( ) )
147+ . do_update ( )
148+ . set ( crate_owners:: deleted. eq ( false ) )
149+ . execute ( conn)
150+ . await ?;
151+
152+ diesel:: delete ( & self ) . execute ( conn) . await ?;
153+
154+ Ok ( ( ) )
155+ }
156+ . scope_boxed ( )
147157 } )
158+ . await
148159 }
149160
150- pub fn decline ( self , conn : & mut impl Conn ) -> QueryResult < ( ) > {
151- use diesel :: RunQueryDsl ;
161+ pub async fn decline ( self , conn : & mut AsyncPgConnection ) -> QueryResult < ( ) > {
162+ use diesel_async :: RunQueryDsl ;
152163
153164 // The check to prevent declining expired invitations is *explicitly* missing. We do not
154165 // care if an expired invitation is declined, as that just removes the invitation from the
155166 // database.
156167
157- diesel:: delete ( & self ) . execute ( conn) ?;
168+ diesel:: delete ( & self ) . execute ( conn) . await ?;
158169 Ok ( ( ) )
159170 }
160171
0 commit comments