From 0f3245c90eb624e14cfd293cf8acba9bb014531e Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Wed, 15 Jun 2022 11:38:18 +0200 Subject: [PATCH] Fix delete --- api/delete_report.go | 11 ++++------- scenario/integration.yml | 9 +-------- state/state.go | 12 ++++++++++++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/api/delete_report.go b/api/delete_report.go index 2a33fa5..3188142 100644 --- a/api/delete_report.go +++ b/api/delete_report.go @@ -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" ) @@ -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) } diff --git a/scenario/integration.yml b/scenario/integration.yml index ac9a301..2b2a413 100644 --- a/scenario/integration.yml +++ b/scenario/integration.yml @@ -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": {}, @@ -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} diff --git a/state/state.go b/state/state.go index ba0743f..f87e539 100644 --- a/state/state.go +++ b/state/state.go @@ -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{}} @@ -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 {