Skip to content

Commit 3763b65

Browse files
fix: git material saved in transaction (#5040)
* git material flow added in transaction * wire refactored * code review comments incorporated * code review comments incorporated * code review comments incorporated
1 parent 0159828 commit 3763b65

19 files changed

+103
-72
lines changed

Wire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func InitializeApp() (*App, error) {
226226
wire.Bind(new(router.PProfRouter), new(*router.PProfRouterImpl)),
227227
// ---- pprof end ----
228228

229+
sql.NewTransactionUtilImpl,
230+
wire.Bind(new(sql.TransactionWrapper), new(*sql.TransactionUtilImpl)),
231+
229232
trigger.NewPipelineRestHandler,
230233
wire.Bind(new(trigger.PipelineTriggerRestHandler), new(*trigger.PipelineTriggerRestHandlerImpl)),
231234
app.GetAppServiceConfig,

cmd/external-app/wire.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ func InitializeApp() (*App, error) {
103103
telemetry.NewPosthogClient,
104104
delete2.NewDeleteServiceImpl,
105105

106+
sql.NewTransactionUtilImpl,
107+
106108
pipelineConfig.NewMaterialRepositoryImpl,
107109
wire.Bind(new(pipelineConfig.MaterialRepository), new(*pipelineConfig.MaterialRepositoryImpl)),
108110
// appStatus

cmd/external-app/wire_gen.go

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/repository/imageTagging/ImageTaggingRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ type ImageTaggingRepositoryImpl struct {
8585
*sql.TransactionUtilImpl
8686
}
8787

88-
func NewImageTaggingRepositoryImpl(db *pg.DB) *ImageTaggingRepositoryImpl {
88+
func NewImageTaggingRepositoryImpl(db *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *ImageTaggingRepositoryImpl {
8989
return &ImageTaggingRepositoryImpl{
9090
dbConnection: db,
91-
TransactionUtilImpl: sql.NewTransactionUtilImpl(db),
91+
TransactionUtilImpl: TransactionUtilImpl,
9292
}
9393
}
9494

internal/sql/repository/pipelineConfig/CiPipelineRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ type CiPipelineRepositoryImpl struct {
150150
*sql.TransactionUtilImpl
151151
}
152152

153-
func NewCiPipelineRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *CiPipelineRepositoryImpl {
153+
func NewCiPipelineRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger, TransactionUtilImpl *sql.TransactionUtilImpl) *CiPipelineRepositoryImpl {
154154
return &CiPipelineRepositoryImpl{
155155
dbConnection: dbConnection,
156156
logger: logger,
157-
TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection),
157+
TransactionUtilImpl: TransactionUtilImpl,
158158
}
159159
}
160160

internal/sql/repository/pipelineConfig/MaterialRepository.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ type GitMaterial struct {
5252

5353
type MaterialRepository interface {
5454
MaterialExists(url string) (bool, error)
55-
SaveMaterial(material *GitMaterial) error
56-
UpdateMaterial(material *GitMaterial) error
55+
SaveMaterial(tx *pg.Tx, material *GitMaterial) error
56+
UpdateMaterial(tx *pg.Tx, material *GitMaterial) error
5757
Update(materials []*GitMaterial) error
5858
FindByAppId(appId int) ([]*GitMaterial, error)
5959
FindById(Id int) (*GitMaterial, error)
6060
FindByAppIdAndGitMaterialId(appId, id int) (*GitMaterial, error)
6161
UpdateMaterialScmId(material *GitMaterial) error
6262
FindByAppIdAndCheckoutPath(appId int, checkoutPath string) (*GitMaterial, error)
6363
FindByGitProviderId(gitProviderId int) (materials []*GitMaterial, err error)
64-
MarkMaterialDeleted(material *GitMaterial) error
64+
MarkMaterialDeleted(tx *pg.Tx, material *GitMaterial) error
6565
FindNumberOfAppsWithGitRepo(appIds []int) (int, error)
6666
FindByAppIds(appIds []int) ([]*GitMaterial, error)
6767
}
@@ -113,12 +113,12 @@ func (repo MaterialRepositoryImpl) MaterialExists(url string) (bool, error) {
113113
return exists, err
114114
}
115115

116-
func (repo MaterialRepositoryImpl) SaveMaterial(material *GitMaterial) error {
117-
return repo.dbConnection.Insert(material)
116+
func (repo MaterialRepositoryImpl) SaveMaterial(tx *pg.Tx, material *GitMaterial) error {
117+
return tx.Insert(material)
118118
}
119119

120-
func (repo MaterialRepositoryImpl) UpdateMaterial(material *GitMaterial) error {
121-
return repo.dbConnection.Update(material)
120+
func (repo MaterialRepositoryImpl) UpdateMaterial(tx *pg.Tx, material *GitMaterial) error {
121+
return tx.Update(material)
122122
}
123123

124124
func (repo MaterialRepositoryImpl) UpdateMaterialScmId(material *GitMaterial) error {
@@ -164,9 +164,9 @@ func (repo MaterialRepositoryImpl) FindByGitProviderId(gitProviderId int) (mater
164164
return materials, err
165165
}
166166

167-
func (repo MaterialRepositoryImpl) MarkMaterialDeleted(material *GitMaterial) error {
167+
func (repo MaterialRepositoryImpl) MarkMaterialDeleted(tx *pg.Tx, material *GitMaterial) error {
168168
material.Active = false
169-
return repo.dbConnection.Update(material)
169+
return tx.Update(material)
170170
}
171171

172172
func (repo MaterialRepositoryImpl) FindNumberOfAppsWithGitRepo(appIds []int) (int, error) {

pkg/chartRepo/repository/ChartsRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ type ChartRepository interface {
5858
sql.TransactionWrapper
5959
}
6060

61-
func NewChartRepository(dbConnection *pg.DB) *ChartRepositoryImpl {
61+
func NewChartRepository(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *ChartRepositoryImpl {
6262
return &ChartRepositoryImpl{
6363
dbConnection: dbConnection,
64-
TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection),
64+
TransactionUtilImpl: TransactionUtilImpl,
6565
}
6666
}
6767

pkg/cluster/repository/EphemeralContainersRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ type EphemeralContainersRepository interface {
4040
FindContainerByName(clusterID int, namespace, podName, name string) (*EphemeralContainerBean, error)
4141
}
4242

43-
func NewEphemeralContainersRepositoryImpl(db *pg.DB) *EphemeralContainersRepositoryImpl {
43+
func NewEphemeralContainersRepositoryImpl(db *pg.DB, transactionUtilImpl *sql.TransactionUtilImpl) *EphemeralContainersRepositoryImpl {
4444
return &EphemeralContainersRepositoryImpl{
4545
dbConnection: db,
46-
TransactionUtilImpl: sql.NewTransactionUtilImpl(db),
46+
TransactionUtilImpl: transactionUtilImpl,
4747
}
4848
}
4949

pkg/genericNotes/repository/GenericNoteHistoryRepository.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type GenericNoteHistoryRepository interface {
3636
FindHistoryByNoteId(id []int) ([]GenericNoteHistory, error)
3737
}
3838

39-
func NewGenericNoteHistoryRepositoryImpl(dbConnection *pg.DB) *GenericNoteHistoryRepositoryImpl {
40-
TransactionUtilImpl := sql.NewTransactionUtilImpl(dbConnection)
39+
func NewGenericNoteHistoryRepositoryImpl(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *GenericNoteHistoryRepositoryImpl {
4140
return &GenericNoteHistoryRepositoryImpl{
4241
dbConnection: dbConnection,
4342
TransactionUtilImpl: TransactionUtilImpl,

pkg/genericNotes/repository/GenericNoteRepository.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ type GenericNoteRepository interface {
5151
GetDescriptionFromAppIds(appIds []int) ([]*GenericNote, error)
5252
}
5353

54-
func NewGenericNoteRepositoryImpl(dbConnection *pg.DB) *GenericNoteRepositoryImpl {
55-
TransactionUtilImpl := sql.NewTransactionUtilImpl(dbConnection)
54+
func NewGenericNoteRepositoryImpl(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *GenericNoteRepositoryImpl {
5655
return &GenericNoteRepositoryImpl{
5756
dbConnection: dbConnection,
5857
TransactionUtilImpl: TransactionUtilImpl,

0 commit comments

Comments
 (0)