jobqueue: do not sort dependencies
While dependencies are purely internal, sorting and pruning them is a reasonable optimization. However, we wish to expose them in follow-up commits and then we want them to remain unchanged from the input. Nothing in the internal logic seems to rely on the fact the dependencies were sorted. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
f355bdd426
commit
e72b14bdd1
3 changed files with 2 additions and 88 deletions
|
|
@ -17,7 +17,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -108,7 +107,7 @@ func (q *fsJobQueue) Enqueue(jobType string, args interface{}, dependencies []uu
|
|||
var j = job{
|
||||
Id: uuid.New(),
|
||||
Type: jobType,
|
||||
Dependencies: uniqueUUIDList(dependencies),
|
||||
Dependencies: dependencies,
|
||||
QueuedAt: time.Now(),
|
||||
}
|
||||
|
||||
|
|
@ -336,30 +335,6 @@ func (q *fsJobQueue) maybeEnqueue(j *job, updateDependants bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Sorts and removes duplicates from `ids`.
|
||||
func uniqueUUIDList(ids []uuid.UUID) []uuid.UUID {
|
||||
s := map[uuid.UUID]bool{}
|
||||
for _, id := range ids {
|
||||
s[id] = true
|
||||
}
|
||||
|
||||
l := []uuid.UUID{}
|
||||
for id := range s {
|
||||
l = append(l, id)
|
||||
}
|
||||
|
||||
sort.Slice(l, func(i, j int) bool {
|
||||
for b := 0; b < 16; b++ {
|
||||
if l[i][b] < l[j][b] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// Select on a list of `chan uuid.UUID`s. Returns an error if one of the
|
||||
// channels is closed.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
package fsjobqueue
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func uuidList(t *testing.T, strs ...string) []uuid.UUID {
|
||||
var err error
|
||||
ids := make([]uuid.UUID, len(strs))
|
||||
for i, s := range strs {
|
||||
ids[i], err = uuid.Parse(s)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func TestUniqueUUIDList(t *testing.T) {
|
||||
l := uniqueUUIDList([]uuid.UUID{})
|
||||
require.Empty(t, l)
|
||||
|
||||
s := uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "a0ad7428-b813-4efb-a156-da2b524f4868", "36e5817c-f29d-4043-8d7d-95ffaa77ff88")
|
||||
l = uniqueUUIDList(s)
|
||||
require.ElementsMatch(t, s, l)
|
||||
|
||||
s = uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2")
|
||||
l = uniqueUUIDList(s)
|
||||
require.ElementsMatch(t, uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2"), l)
|
||||
|
||||
s = uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "a0ad7428-b813-4efb-a156-da2b524f4868", "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2")
|
||||
l = uniqueUUIDList(s)
|
||||
require.ElementsMatch(t, uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "a0ad7428-b813-4efb-a156-da2b524f4868"), l)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue