File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -141,9 +141,20 @@ class SeatsService {
141141 assignee : updatedMembers . find ( m => m . id === seat . assignee . id ) ?. _id
142142 } ) ) ;
143143 logger . debug ( `Writing ${ seatsData . length } seats` ) ;
144- const seatResults = await Seats . insertMany ( seatsData ) ;
145144
146- // Add member seat updates
145+ const seatInsertOperations = seatsData . map ( seat => ( {
146+ insertOne : {
147+ document : seat
148+ }
149+ } ) ) ;
150+ const bulkWriteResult = await Seats . bulkWrite ( seatInsertOperations , { ordered : false } ) ;
151+ logger . debug ( `Inserted ${ bulkWriteResult . insertedCount } seats` ) ;
152+ const seatResults = await Seats . find ( {
153+ queryAt,
154+ org,
155+ assignee_id : { $in : data . map ( seat => seat . assignee . id ) }
156+ } ) . sort ( { createdAt : - 1 } ) . limit ( seatsData . length ) ;
157+
147158 const memberSeatUpdates = seatResults . map ( seat => ( {
148159 updateOne : {
149160 filter : { org, id : seat . assignee_id } ,
@@ -169,7 +180,6 @@ class SeatsService {
169180 _seat : seat . _id ,
170181 } ) )
171182 }
172-
173183 logger . debug ( `Writing ${ adoptionData . seats . length } adoption data` ) ;
174184 await adoptionService . createAdoption ( adoptionData ) ;
175185
You can’t perform that action at this time.
0 commit comments