Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions drivers/pg/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/specterops/dawgs/graph"
"github.com/specterops/dawgs/util/size"
)

var (
Expand Down Expand Up @@ -40,10 +41,10 @@ type Driver struct {
*SchemaManager
}

func NewDriver(pool *pgxpool.Pool) *Driver {
func NewDriver(graphQueryMemoryLimit size.Size, pool *pgxpool.Pool) *Driver {
return &Driver{
pool: pool,
SchemaManager: NewSchemaManager(pool),
SchemaManager: NewSchemaManager(pool, graphQueryMemoryLimit),
}
}

Expand Down
31 changes: 17 additions & 14 deletions drivers/pg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/specterops/dawgs/drivers/pg/model"
"github.com/specterops/dawgs/drivers/pg/query"
"github.com/specterops/dawgs/graph"
"github.com/specterops/dawgs/util/size"
)

type KindMapper interface {
Expand All @@ -32,23 +33,25 @@ func KindMapperFromGraphDatabase(graphDB graph.Database) (KindMapper, error) {
}

type SchemaManager struct {
defaultGraph model.Graph
pool *pgxpool.Pool
hasDefaultGraph bool
graphs map[string]model.Graph
kindsByID map[graph.Kind]int16
kindIDsByKind map[int16]graph.Kind
lock *sync.RWMutex
defaultGraph model.Graph
pool *pgxpool.Pool
hasDefaultGraph bool
graphs map[string]model.Graph
kindsByID map[graph.Kind]int16
kindIDsByKind map[int16]graph.Kind
lock *sync.RWMutex
graphQueryMemoryLimit size.Size
}

func NewSchemaManager(pool *pgxpool.Pool) *SchemaManager {
func NewSchemaManager(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size) *SchemaManager {
return &SchemaManager{
pool: pool,
hasDefaultGraph: false,
graphs: map[string]model.Graph{},
kindsByID: map[graph.Kind]int16{},
kindIDsByKind: map[int16]graph.Kind{},
lock: &sync.RWMutex{},
pool: pool,
hasDefaultGraph: false,
graphs: map[string]model.Graph{},
kindsByID: map[graph.Kind]int16{},
kindIDsByKind: map[int16]graph.Kind{},
lock: &sync.RWMutex{},
graphQueryMemoryLimit: graphQueryMemoryLimit,
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/pg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ func NewPool(connectionString string) (*pgxpool.Pool, error) {

func init() {
dawgs.Register(DriverName, func(ctx context.Context, cfg dawgs.Config) (graph.Database, error) {
return NewDriver(cfg.Pool), nil
return NewDriver(cfg.GraphQueryMemoryLimit, cfg.Pool), nil
})
}
2 changes: 1 addition & 1 deletion drivers/pg/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *transaction) driver() driver {
}

func (s *transaction) GraphQueryMemoryLimit() size.Size {
return size.Gibibyte
return s.schemaManager.graphQueryMemoryLimit
}

func (s *transaction) WithGraph(schema graph.Graph) graph.Transaction {
Expand Down