Skip to content

Commit

Permalink
fix: remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Mar 10, 2020
1 parent c02281b commit 123889d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 164 deletions.
14 changes: 14 additions & 0 deletions internal/dvstore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ func LoadTasks(h *cayley.Handle, schema *schema.Config, filters LoadTasksFilters
tasks = dvmodel.FilterIsolatedTasks(tasks, logger)
}

{ // remove duplicates
// FIXME: remove duplicates from the query itself
taskMap := map[quad.IRI]dvmodel.Task{}
for _, task := range tasks {
taskMap[task.ID] = task
}
tasks = make(dvmodel.Tasks, len(taskMap))
i := 0
for _, task := range taskMap {
tasks[i] = task
i++
}
}

sort.Slice(tasks[:], func(i, j int) bool {
return tasks[i].ID < tasks[j].ID
})
Expand Down
16 changes: 16 additions & 0 deletions internal/dvstore/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ func TestLoadTasks(t *testing.T) {
assert.NoError(t, err, name)
}

{ // check for duplicates
duplicateMap := map[string]int{}
hasDuplicates := false
for _, task := range tasks {
if _, found := duplicateMap[string(task.ID)]; !found {
duplicateMap[string(task.ID)] = 0
} else {
hasDuplicates = true
}
duplicateMap[string(task.ID)]++
}
if !assert.False(t, hasDuplicates) {
fmt.Println(godev.PrettyJSON(duplicateMap))
}
}

g, err := ioutil.ReadFile(gp)
assert.NoError(t, err, name)
assert.Equal(t, len(string(g)), len(actual), gp)
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 123889d

Please sign in to comment.