@@ -6,7 +6,7 @@ import { Redis } from "ioredis";
66import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js" ;
77import { env } from "../env.js" ;
88import { createOctokitFromToken , getReposForAuthenticatedUser } from "../github.js" ;
9- import { createGitLabFromOAuthToken , createGitLabFromPersonalAccessToken , getProjectsForAuthenticatedUser } from "../gitlab.js" ;
9+ import { createGitLabFromOAuthToken , getProjectsForAuthenticatedUser } from "../gitlab.js" ;
1010import { hasEntitlement } from "@sourcebot/shared" ;
1111import { Settings } from "../types.js" ;
1212
@@ -113,24 +113,25 @@ export class UserPermissionSyncer {
113113 }
114114
115115 private async schedulePermissionSync ( users : User [ ] ) {
116- await this . db . $transaction ( async ( tx ) => {
117- const jobs = await tx . userPermissionSyncJob . createManyAndReturn ( {
118- data : users . map ( user => ( {
119- userId : user . id ,
120- } ) ) ,
121- } ) ;
122-
123- await this . queue . addBulk ( jobs . map ( ( job ) => ( {
124- name : 'userPermissionSyncJob' ,
125- data : {
126- jobId : job . id ,
127- } ,
128- opts : {
129- removeOnComplete : env . REDIS_REMOVE_ON_COMPLETE ,
130- removeOnFail : env . REDIS_REMOVE_ON_FAIL ,
131- }
132- } ) ) )
116+ // @note : we don't perform this in a transaction because
117+ // we want to avoid the situation where a job is created and run
118+ // prior to the transaction being committed.
119+ const jobs = await this . db . userPermissionSyncJob . createManyAndReturn ( {
120+ data : users . map ( user => ( {
121+ userId : user . id ,
122+ } ) ) ,
133123 } ) ;
124+
125+ await this . queue . addBulk ( jobs . map ( ( job ) => ( {
126+ name : 'userPermissionSyncJob' ,
127+ data : {
128+ jobId : job . id ,
129+ } ,
130+ opts : {
131+ removeOnComplete : env . REDIS_REMOVE_ON_COMPLETE ,
132+ removeOnFail : env . REDIS_REMOVE_ON_FAIL ,
133+ }
134+ } ) ) )
134135 }
135136
136137 private async runJob ( job : Job < UserPermissionSyncJob > ) {
0 commit comments