inklabs/rangedb

View on GitHub
provider/eventstore/eventstore.go

Summary

Maintainability
F
5 days
Test Coverage
D
68%

Showing 21 of 21 total issues

File eventstore.go has 760 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package eventstore
 
import (
"bytes"
"context"
Severity: Major
Found in provider/eventstore/eventstore.go - About 1 day to fix

    Method eventStore.EventsByStream has a Cognitive Complexity of 49 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *eventStore) EventsByStream(ctx context.Context, streamSequenceNumber uint64, streamName string) rangedb.RecordIterator {
    resultRecords := make(chan rangedb.ResultRecord)
     
    go func() {
    defer close(resultRecords)
    Severity: Minor
    Found in provider/eventstore/eventstore.go - About 5 hrs to fix

    Method eventStore.Events has a Cognitive Complexity of 46 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *eventStore) Events(ctx context.Context, globalSequenceNumber uint64) rangedb.RecordIterator {
    resultRecords := make(chan rangedb.ResultRecord)
     
    go func() {
    defer close(resultRecords)
    Severity: Minor
    Found in provider/eventstore/eventstore.go - About 4 hrs to fix

    Method eventStore.EventsByAggregateTypes has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *eventStore) EventsByAggregateTypes(ctx context.Context, globalSequenceNumber uint64, aggregateTypes ...string) rangedb.RecordIterator {
    resultRecords := make(chan rangedb.ResultRecord)
     
    go func() {
    defer close(resultRecords)
    Severity: Minor
    Found in provider/eventstore/eventstore.go - About 4 hrs to fix

    Method eventStore.EventsByStream has 100 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (s *eventStore) EventsByStream(ctx context.Context, streamSequenceNumber uint64, streamName string) rangedb.RecordIterator {
    resultRecords := make(chan rangedb.ResultRecord)
     
    go func() {
    defer close(resultRecords)
    Severity: Major
    Found in provider/eventstore/eventstore.go - About 3 hrs to fix

      Method eventStore.Events has 85 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (s *eventStore) Events(ctx context.Context, globalSequenceNumber uint64) rangedb.RecordIterator {
      resultRecords := make(chan rangedb.ResultRecord)
       
      go func() {
      defer close(resultRecords)
      Severity: Major
      Found in provider/eventstore/eventstore.go - About 2 hrs to fix

        eventStore has 22 methods (exceeds 20 allowed). Consider refactoring.
        Open

        type eventStore struct {
        client *esdb.Client
        clock clock.Clock
        streamPrefixer StreamPrefixer
        uuidGenerator shortuuid.Generator
        Severity: Minor
        Found in provider/eventstore/eventstore.go - About 2 hrs to fix

          Method eventStore.EventsByAggregateTypes has 79 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (s *eventStore) EventsByAggregateTypes(ctx context.Context, globalSequenceNumber uint64, aggregateTypes ...string) rangedb.RecordIterator {
          resultRecords := make(chan rangedb.ResultRecord)
           
          go func() {
          defer close(resultRecords)
          Severity: Major
          Found in provider/eventstore/eventstore.go - About 2 hrs to fix

            Method eventStore.saveEvents has 77 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (s *eventStore) saveEvents(ctx context.Context, expectedStreamSequenceNumber *uint64, streamName string, eventRecords ...*rangedb.EventRecord) (uint64, error) {
            if len(eventRecords) < 1 {
            return 0, fmt.Errorf("missing events")
            }
             
             
            Severity: Major
            Found in provider/eventstore/eventstore.go - About 2 hrs to fix

              Method eventStore.startSubscription has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
              Open

              func (s *eventStore) startSubscription() {
              ctx := context.Background()
              opts := esdb.SubscribeToAllOptions{
              From: esdb.Start{},
              }
              Severity: Minor
              Found in provider/eventstore/eventstore.go - About 1 hr to fix

              Method eventStore.startSubscription has 55 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (s *eventStore) startSubscription() {
              ctx := context.Background()
              opts := esdb.SubscribeToAllOptions{
              From: esdb.Start{},
              }
              Severity: Minor
              Found in provider/eventstore/eventstore.go - About 1 hr to fix

                Method eventStore.Events has 11 return statements (exceeds 4 allowed).
                Open

                func (s *eventStore) Events(ctx context.Context, globalSequenceNumber uint64) rangedb.RecordIterator {
                resultRecords := make(chan rangedb.ResultRecord)
                 
                go func() {
                defer close(resultRecords)
                Severity: Major
                Found in provider/eventstore/eventstore.go - About 1 hr to fix

                  Method eventStore.EventsByStream has 11 return statements (exceeds 4 allowed).
                  Open

                  func (s *eventStore) EventsByStream(ctx context.Context, streamSequenceNumber uint64, streamName string) rangedb.RecordIterator {
                  resultRecords := make(chan rangedb.ResultRecord)
                   
                  go func() {
                  defer close(resultRecords)
                  Severity: Major
                  Found in provider/eventstore/eventstore.go - About 1 hr to fix

                    Method eventStore.saveEvents has 10 return statements (exceeds 4 allowed).
                    Open

                    func (s *eventStore) saveEvents(ctx context.Context, expectedStreamSequenceNumber *uint64, streamName string, eventRecords ...*rangedb.EventRecord) (uint64, error) {
                    if len(eventRecords) < 1 {
                    return 0, fmt.Errorf("missing events")
                    }
                     
                     
                    Severity: Major
                    Found in provider/eventstore/eventstore.go - About 1 hr to fix

                      Method eventStore.startSubscription has 8 return statements (exceeds 4 allowed).
                      Open

                      func (s *eventStore) startSubscription() {
                      ctx := context.Background()
                      opts := esdb.SubscribeToAllOptions{
                      From: esdb.Start{},
                      }
                      Severity: Major
                      Found in provider/eventstore/eventstore.go - About 50 mins to fix

                        Method eventStore.EventsByAggregateTypes has 8 return statements (exceeds 4 allowed).
                        Open

                        func (s *eventStore) EventsByAggregateTypes(ctx context.Context, globalSequenceNumber uint64, aggregateTypes ...string) rangedb.RecordIterator {
                        resultRecords := make(chan rangedb.ResultRecord)
                         
                        go func() {
                        defer close(resultRecords)
                        Severity: Major
                        Found in provider/eventstore/eventstore.go - About 50 mins to fix

                          Method eventStore.OptimisticDeleteStream has 6 return statements (exceeds 4 allowed).
                          Open

                          func (s *eventStore) OptimisticDeleteStream(ctx context.Context, expectedStreamSequenceNumber uint64, streamName string) error {
                          versionedStreamName := s.streamName(streamName)
                          tombstoneStreamOptions := esdb.TombstoneStreamOptions{
                          ExpectedRevision: esdb.Revision(zeroBasedSequenceNumber(expectedStreamSequenceNumber)),
                          Authenticated: nil,
                          Severity: Major
                          Found in provider/eventstore/eventstore.go - About 40 mins to fix

                            Method eventStore.waitForScavenge has 6 return statements (exceeds 4 allowed).
                            Open

                            func (s *eventStore) waitForScavenge(ctx context.Context) {
                            log.Print("starting scavenge")
                            uri := "http://0.0.0.0:2113/admin/scavenge"
                            req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, nil)
                            if err != nil {
                            Severity: Major
                            Found in provider/eventstore/eventstore.go - About 40 mins to fix

                              Method eventStore.saveEvents has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                              Open

                              func (s *eventStore) saveEvents(ctx context.Context, expectedStreamSequenceNumber *uint64, streamName string, eventRecords ...*rangedb.EventRecord) (uint64, error) {
                              if len(eventRecords) < 1 {
                              return 0, fmt.Errorf("missing events")
                              }
                               
                               
                              Severity: Minor
                              Found in provider/eventstore/eventstore.go - About 35 mins to fix

                              Similar blocks of code found in 5 locations. Consider refactoring.
                              Open

                              func (s *eventStore) AggregateTypesSubscription(ctx context.Context, bufferSize int, subscriber rangedb.RecordSubscriber, aggregateTypes ...string) rangedb.RecordSubscription {
                              return recordsubscriber.New(
                              recordsubscriber.AggregateTypesConfig(ctx, s, s.broadcaster, bufferSize,
                              aggregateTypes,
                              func(record *rangedb.Record) error {
                              Severity: Major
                              Found in provider/eventstore/eventstore.go and 4 other locations - About 1 hr to fix
                              provider/inmemorystore/inmemory_store.go on lines 373..382
                              provider/leveldbstore/leveldb_store.go on lines 344..353
                              provider/postgresstore/postgres_store.go on lines 350..359
                              provider/remotestore/remote_store.go on lines 277..286

                              Similar blocks of code found in 5 locations. Consider refactoring.
                              Open

                              func (s *eventStore) AllEventsSubscription(ctx context.Context, bufferSize int, subscriber rangedb.RecordSubscriber) rangedb.RecordSubscription {
                              return recordsubscriber.New(
                              recordsubscriber.AllEventsConfig(ctx, s, s.broadcaster, bufferSize,
                              func(record *rangedb.Record) error {
                              subscriber.Accept(record)
                              Severity: Major
                              Found in provider/eventstore/eventstore.go and 4 other locations - About 50 mins to fix
                              provider/inmemorystore/inmemory_store.go on lines 363..371
                              provider/leveldbstore/leveldb_store.go on lines 334..342
                              provider/postgresstore/postgres_store.go on lines 340..348
                              provider/remotestore/remote_store.go on lines 267..275
                              Category
                              Status