Skip to content

Commit

Permalink
Follow DBS logic in fileparents API
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed May 7, 2022
1 parent 002af65 commit 2b6cf0d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbs/fileparents.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (a *API) InsertFileParentsBlockTxt(tx *sql.Tx) error {
if utils.VERBOSE > 1 {
log.Println("InsertFileParentsBlock fids", fids, "bfids", bfids)
}
if len(fids) != len(bfids) {
if !utils.Equal(utils.Set(fids), utils.Set(bfids)) {
log.Println("block fids != file ids")
log.Println("block ids", bfids)
log.Println("file ids", fids)
Expand Down
13 changes: 13 additions & 0 deletions test/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ func TestUtilsInList(t *testing.T) {
}
}

// TestUtilsSet
func TestUtilsSet(t *testing.T) {
vals := []int64{1, 2, 3, 1}
res := utils.Set(vals)
if !utils.Equal(res, []int64{1, 2, 3}) {
t.Error("Fail TestUtilsSet")
}
arr := []int64{4, 5, 6}
if utils.Equal(res, arr) {
t.Error("Fail of Equal in TestUtilsSet")
}
}

// TestUtilsRecordSize
func TestUtilsRecordSize(t *testing.T) {
rec := make(map[string]int)
Expand Down
25 changes: 25 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ func InList(a string, list []string) bool {
return false
}

// Set implementa basic set
func Set(list []int64) []int64 {
var out []int64
for _, v := range list {
if !InInt64List(v, out) {
out = append(out, v)
}
}
return out
}

// Equal tells whether a and b contain the same elements.
// A nil argument is equivalent to an empty slice.
func Equal(a, b []int64) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}

// MapKeys returns string keys from a map
func MapKeys(rec map[string]interface{}) []string {
keys := make([]string, 0, len(rec))
Expand Down

0 comments on commit 2b6cf0d

Please sign in to comment.