inklabs/rangedb

View on GitHub
provider/postgresstore/postgres_store.go

Summary

Maintainability
D
2 days
Test Coverage
A
91%

Showing 12 of 12 total issues

File postgres_store.go has 671 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package postgresstore
 
import (
"context"
"database/sql"
Severity: Minor
Found in provider/postgresstore/postgres_store.go - About 6 hrs to fix

    postgresStore has 24 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type postgresStore struct {
    config *Config
    db *sql.DB
    clock clock.Clock
    uuidGenerator shortuuid.Generator
    Severity: Minor
    Found in provider/postgresstore/postgres_store.go - About 2 hrs to fix

      Method postgresStore.readResultRecords has 72 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (s *postgresStore) readResultRecords(ctx context.Context, rows *sql.Rows, resultRecords chan rangedb.ResultRecord) (int, error) {
      recordsRead := 0
      for rows.Next() {
      var (
      streamName string
      Severity: Minor
      Found in provider/postgresstore/postgres_store.go - About 1 hr to fix

        Method postgresStore.OptimisticDeleteStream has 7 return statements (exceeds 4 allowed).
        Open

        func (s *postgresStore) OptimisticDeleteStream(ctx context.Context, expectedStreamSequenceNumber uint64, streamName string) error {
        transaction, err := s.db.BeginTx(ctx, nil)
        if err != nil {
        return err
        }
        Severity: Major
        Found in provider/postgresstore/postgres_store.go - About 45 mins to fix

          Method postgresStore.readResultRecords has 6 return statements (exceeds 4 allowed).
          Open

          func (s *postgresStore) readResultRecords(ctx context.Context, rows *sql.Rows, resultRecords chan rangedb.ResultRecord) (int, error) {
          recordsRead := 0
          for rows.Next() {
          var (
          streamName string
          Severity: Major
          Found in provider/postgresstore/postgres_store.go - About 40 mins to fix

            Method postgresStore.saveEvents has 6 return statements (exceeds 4 allowed).
            Open

            func (s *postgresStore) saveEvents(
            ctx context.Context,
            transaction *sql.Tx,
            expectedStreamSequenceNumber *uint64,
            streamName string,
            Severity: Major
            Found in provider/postgresstore/postgres_store.go - About 40 mins to fix

              Method postgresStore.saveEvents has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              ctx context.Context,
              transaction *sql.Tx,
              expectedStreamSequenceNumber *uint64,
              streamName string,
              eventRecords []*rangedb.EventRecord,
              Severity: Minor
              Found in provider/postgresstore/postgres_store.go - About 35 mins to fix

                Method postgresStore.eventRecordsToBatchRecords has 5 return statements (exceeds 4 allowed).
                Open

                func (s *postgresStore) eventRecordsToBatchRecords(eventRecords []*rangedb.EventRecord, streamName string, streamSequenceNumber uint64) ([]*batchSQLRecord, error) {
                aggregateType := eventRecords[0].Event.AggregateType()
                aggregateID := eventRecords[0].Event.AggregateID()
                 
                var batchEvents []*batchSQLRecord
                Severity: Major
                Found in provider/postgresstore/postgres_store.go - About 35 mins to fix

                  Method postgresStore.transactionalSaveEvents has 5 return statements (exceeds 4 allowed).
                  Open

                  func (s *postgresStore) transactionalSaveEvents(ctx context.Context, expectedStreamSequenceNumber *uint64, streamName string, eventRecords ...*rangedb.EventRecord) (uint64, error) {
                  transaction, err := s.db.BeginTx(ctx, nil)
                  if err != nil {
                  return 0, err
                  }
                  Severity: Major
                  Found in provider/postgresstore/postgres_store.go - About 35 mins to fix

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

                    func (s *postgresStore) 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/postgresstore/postgres_store.go and 4 other locations - About 1 hr to fix
                    provider/eventstore/eventstore.go on lines 584..593
                    provider/inmemorystore/inmemory_store.go on lines 373..382
                    provider/leveldbstore/leveldb_store.go on lines 344..353
                    provider/remotestore/remote_store.go on lines 277..286

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

                    func (s *postgresStore) 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/postgresstore/postgres_store.go and 4 other locations - About 50 mins to fix
                    provider/eventstore/eventstore.go on lines 574..582
                    provider/inmemorystore/inmemory_store.go on lines 363..371
                    provider/leveldbstore/leveldb_store.go on lines 334..342
                    provider/remotestore/remote_store.go on lines 267..275

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

                    func (s *postgresStore) connectToDB() error {
                    db, err := sql.Open("postgres", s.config.DataSourceName())
                    if err != nil {
                    return fmt.Errorf("unable to open DB connection: %v", err)
                    }
                    Severity: Minor
                    Found in provider/postgresstore/postgres_store.go and 1 other location - About 50 mins to fix
                    pkg/crypto/provider/postgreskeystore/postgres_keystore.go on lines 100..114
                    Category
                    Status