Skip to content

Commit 75a31a1

Browse files
committed
Delete pending versions on app removal
1 parent a99c9b6 commit 75a31a1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

registry/finders.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,24 @@ func GetPendingVersions(c *space.Space) ([]*Version, error) {
640640
return versions, nil
641641
}
642642

643+
func GetAppPengindVersions(c *space.Space, appSlug string) ([]*Version, error) {
644+
versions := make([]*Version, 0)
645+
pendingVersions, err := GetPendingVersions(c)
646+
if err != nil {
647+
return nil, err
648+
}
649+
650+
// Filter by appslug
651+
// We could have requested CouchDB with a filter but as we have no index on that table and pending versions number
652+
// should be kept low, there souldn't be a performance problem.
653+
for _, v := range pendingVersions {
654+
if v.Slug == appSlug {
655+
versions = append(versions, v)
656+
}
657+
}
658+
return versions, nil
659+
}
660+
643661
// GetAppChannelVersions returns the versions list of an app channel
644662
func GetAppChannelVersions(c *space.Space, appSlug string, channel Channel) ([]*Version, error) {
645663
var versions []string

registry/registry.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,20 @@ func RemoveAppFromSpace(s *space.Space, appSlug string) error {
11421142
return err
11431143
}
11441144

1145+
// First remove all pending versions for that app
1146+
pendingVersions, err := GetAppPengindVersions(s, appSlug)
1147+
if err != nil {
1148+
return err
1149+
}
1150+
1151+
for _, v := range pendingVersions {
1152+
if err = DeletePendingVersion(s, v); err != nil {
1153+
fmt.Printf("Unable to delete pending version %s/%s: %s\n", v.Slug, v.Version, err)
1154+
continue
1155+
}
1156+
}
1157+
1158+
// Then remove all live versions
11451159
app.Versions, err = FindAppVersionsCacheMiss(s, appSlug, Dev, Concatenated)
11461160
if err != nil {
11471161
return err
@@ -1151,6 +1165,7 @@ func RemoveAppFromSpace(s *space.Space, appSlug string) error {
11511165
return err
11521166
}
11531167

1168+
// And finally remove the app
11541169
db := s.AppsDB()
11551170
_, err = db.Delete(context.Background(), app.ID, app.Rev)
11561171
return err

0 commit comments

Comments
 (0)