Skip to content

Commit feac042

Browse files
committed
Fix: Issue of API duplicate publishing when publishing services
1 parent c8e5b75 commit feac042

5 files changed

Lines changed: 20 additions & 8 deletions

File tree

module/release/iml.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,14 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
7878
return "", fmt.Errorf("cluster not set:%w", err)
7979
}
8080

81-
apis, err := m.apiService.ListInfoForService(ctx, proInfo.Id)
81+
apis, err := m.apiService.ListForService(ctx, proInfo.Id)
8282
if err != nil {
83-
if errors.Is(err, gorm.ErrRecordNotFound) {
84-
return "", errors.New("api not found")
85-
}
8683
return "", err
8784
}
8885
if len(apis) == 0 {
8986
return "", errors.New("api not found")
9087
}
91-
apiUUIDS := utils.SliceToSlice(apis, func(a *api.Info) string {
88+
apiUUIDS := utils.SliceToSlice(apis, func(a *api.API) string {
9289
return a.UUID
9390
})
9491
apiProxy, err := m.apiService.ListLatestCommitProxy(ctx, apiUUIDS...)
@@ -122,10 +119,10 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
122119
return c.Key, c.UUID
123120
})
124121
})
125-
122+
apiInfos, err := m.apiService.ListInfo(ctx, apiUUIDS...)
126123
var newRelease *release.Release
127124
err = m.transaction.Transaction(ctx, func(ctx context.Context) error {
128-
for _, a := range apis {
125+
for _, a := range apiInfos {
129126
err = m.apiService.SaveRequest(ctx, a.UUID, &api.Request{
130127
Path: a.Path,
131128
Methods: a.Methods,

module/router/iml.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,14 @@ func (i *imlRouterModule) Delete(ctx context.Context, serviceId string, apiId st
351351
if err != nil {
352352
return err
353353
}
354-
return i.apiService.Delete(ctx, apiId)
354+
return i.transaction.Transaction(ctx, func(ctx context.Context) error {
355+
err = i.apiService.Delete(ctx, apiId)
356+
if err != nil {
357+
return err
358+
}
359+
return i.apiService.DeleteAPIInfo(ctx, apiId)
360+
})
361+
355362
}
356363

357364
func (i *imlRouterModule) Prefix(ctx context.Context, serviceId string) (string, error) {

service/api/iml.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ type imlAPIService struct {
4141
universally.IServiceDelete
4242
}
4343

44+
func (i *imlAPIService) DeleteAPIInfo(ctx context.Context, aid string) error {
45+
return i.apiInfoStore.SoftDelete(ctx, map[string]interface{}{
46+
"uuid": aid,
47+
})
48+
}
49+
4450
func (i *imlAPIService) DeleteByService(ctx context.Context, serviceId string) error {
4551
return i.store.SoftDelete(ctx, map[string]interface{}{
4652
"service": serviceId,

service/api/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
type IAPIService interface {
1414
universally.IServiceGet[API]
1515
universally.IServiceDelete
16+
DeleteAPIInfo(ctx context.Context, aid string) error
1617
CountByService(ctx context.Context, service string) (int64, error)
1718
CountMapByService(ctx context.Context, service ...string) (map[string]int64, error)
1819
Exist(ctx context.Context, aid string, api *Exist) error

stores/api/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Info struct {
3434
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"` // 更新人
3535
UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:update_at;comment:更新时间"`
3636
Disable bool `gorm:"type:tinyint(1);not null;column:disable;comment:是否禁用 0:否 1:是"`
37+
IsDelete bool `gorm:"type:tinyint(1);not null;column:is_delete;comment:是否删除 0:否 1:是"`
3738
}
3839

3940
func (i *Info) TableName() string {

0 commit comments

Comments
 (0)