Skip to content

Commit

Permalink
added sort to logger & made some optimisations in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-M committed Jan 12, 2023
1 parent 6a99471 commit 05e28a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/proxima-one/indexer-utils-go/pkg/utils"
"github.com/proxima-one/streamdb-client-go/pkg/proximaclient"
"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"
"io"

"time"
Expand Down Expand Up @@ -89,7 +91,10 @@ func (logger *Logger) StartLogging(ctx context.Context, logInterval time.Duratio
continue
}
t.ResetRows()
for streamId, data := range streamDataById {
streamIds := utils.MapKeys(streamDataById)
slices.Sort(streamIds)
for _, streamId := range streamIds {
data := streamDataById[streamId]
if data.firstOffset == nil || data.lastOffset == nil || data.lastProcessedEvent == nil {
continue
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/utils/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,21 @@ func FilterArray[A any](arr []A, fun func(A) bool) (res []A) {
}

func MapToSlice[K comparable, V any](m map[K]V) []V {
res := make([]V, 0, len(m))
res := make([]V, len(m))
i := 0
for _, val := range m {
res = append(res, val)
res[i] = val
i++
}
return res
}

func MapKeys[K comparable, V any](m map[K]V) []K {
res := make([]K, len(m))
i := 0
for key := range m {
res[i] = key
i++
}
return res
}

0 comments on commit 05e28a7

Please sign in to comment.