Skip to content

Commit

Permalink
Fix delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Jun 15, 2022
1 parent dfb2d16 commit 0f3245c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
11 changes: 4 additions & 7 deletions api/delete_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package api
import (
"fmt"
"net/http"
"sort"

"github.com/FACT-Finder/perfably/state"
"github.com/coreos/go-semver/semver"
"github.com/labstack/echo/v4"
)
Expand All @@ -23,12 +23,9 @@ func (a *api) DeleteReport(ctx echo.Context, projectName, version string) error
project.Lock.Lock()
defer project.Lock.Unlock()

idx := sort.Search(len(project.Versions), func(i int) bool {
return !project.Versions[i].LessThan(*id)
project.Add(&state.VersionDataLine{
Version: *id,
Delete: true,
})
if idx < len(project.Versions) && *project.Versions[idx] == *id {
delete(project.Data, *id)
project.Versions = append(project.Versions[:idx], project.Versions[idx+1:]...)
}
return ctx.NoContent(http.StatusNoContent)
}
9 changes: 1 addition & 8 deletions scenario/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,6 @@ steps:
"other": 0.7
}
},
{
"key": "1.0.2",
"meta": {},
"values": {
"custom": 1.8,
"other": 0.8
}
},
{
"key": "1.0.4",
"meta": {},
Expand Down Expand Up @@ -599,3 +591,4 @@ steps:
{"values":{"custom":1.8,"other":0.8},"version":"1.0.2"}
{"values":{"custom":2,"other":1},"version":"1.0.5"}
{"values":{"custom":1.9,"other":0.9},"version":"1.0.4"}
{"version":"1.0.2","delete":true}
12 changes: 12 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ func (p *Project) sortVersions() {
}

func (p *Project) addInternal(line *VersionDataLine) {
if line.Delete {
idx := sort.Search(len(p.Versions), func(i int) bool {
return !p.Versions[i].LessThan(line.Version)
})
if idx < len(p.Versions) && *p.Versions[idx] == line.Version {
delete(p.Data, line.Version)
p.Versions = append(p.Versions[:idx], p.Versions[idx+1:]...)
}
return
}

data, ok := p.Data[line.Version]
if !ok {
data = &VersionData{Values: DataPoint{}, Meta: MetaPoint{}}
Expand All @@ -82,6 +93,7 @@ func (p *Project) addInternal(line *VersionDataLine) {
type VersionDataLine struct {
VersionData
Version semver.Version `json:"version"`
Delete bool `json:"delete,omitempty"`
}

type VersionData struct {
Expand Down

0 comments on commit 0f3245c

Please sign in to comment.