Skip to content

Commit

Permalink
allow to disable query history from config
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimmerGlass committed Jun 28, 2022
1 parent 8f1392b commit 60f9c15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/go-graphkb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
_ "net/http/pprof"

"github.com/clems4ever/go-graphkb/internal/database"
"github.com/clems4ever/go-graphkb/internal/history"
"github.com/clems4ever/go-graphkb/internal/knowledge"
"github.com/clems4ever/go-graphkb/internal/server"
"github.com/sirupsen/logrus"
Expand All @@ -20,6 +21,9 @@ import (
// Database the selected database
var Database *database.MariaDB

// Historizer handles the query history
var Historizer history.Historizer

// ConfigPath string
var ConfigPath string

Expand Down Expand Up @@ -122,6 +126,11 @@ func onInit() {
MaxIdleConns: viper.GetInt("mariadb_max_idle_conns"),
MaxOpenConns: viper.GetInt("mariadb_max_open_conns"),
})

Historizer = Database
if viper.GetBool("no_query_history") {
Historizer = &history.NoopHistorizer{}
}
}

func count(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -155,7 +164,7 @@ func listen(cmd *cobra.Command, args []string) {
concurrency = 32
}

server.StartServer(listenInterface, Database, Database, Database, Database, concurrency)
server.StartServer(listenInterface, Database, Database, Database, Historizer, concurrency)
}

func read(cmd *cobra.Command, args []string) {
Expand Down
10 changes: 10 additions & 0 deletions internal/history/historizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ type Historizer interface {
SaveSuccessfulQuery(ctx context.Context, cypher, sql string, duration time.Duration) error
SaveFailedQuery(ctx context.Context, cypher, sql string, err error) error
}

type NoopHistorizer struct{}

func (h *NoopHistorizer) SaveSuccessfulQuery(ctx context.Context, cypher, sql string, duration time.Duration) error {
return nil
}

func (h *NoopHistorizer) SaveFailedQuery(ctx context.Context, cypher, sql string, err error) error {
return nil
}

0 comments on commit 60f9c15

Please sign in to comment.