From c18e84468915bca2925d7c8768ec962f5f4d1339 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sun, 24 Jul 2022 16:58:03 -0400 Subject: [PATCH] Support more rapid insertion; ignore issues with i/o --- internal/database/database.go | 6 ++++++ sftp/event.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index 6096f70..ebcc06f 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -35,6 +35,12 @@ func Initialize() error { sql.SetMaxOpenConns(1) sql.SetConnMaxLifetime(time.Hour) } + if tx := db.Exec("PRAGMA synchronous = OFF"); tx.Error != nil { + return errors.WithStack(tx.Error) + } + if tx := db.Exec("PRAGMA journal_mode = MEMORY"); tx.Error != nil { + return errors.WithStack(tx.Error) + } if err := db.AutoMigrate(&models.Activity{}); err != nil { return errors.WithStack(err) } diff --git a/sftp/event.go b/sftp/event.go index 28148cf..ff1c7c6 100644 --- a/sftp/event.go +++ b/sftp/event.go @@ -44,7 +44,7 @@ func (eh *eventHandler) Log(e models.Event, fa FileAction) error { } if tx := database.Instance().Create(a.SetUser(eh.user)); tx.Error != nil { - return errors.Wrap(tx.Error, "sftp: failed to save event to database") + return errors.WithStack(tx.Error) } return nil } @@ -53,6 +53,6 @@ func (eh *eventHandler) Log(e models.Event, fa FileAction) error { // if an error is encountered during the logging of the event. func (eh *eventHandler) MustLog(e models.Event, fa FileAction) { if err := eh.Log(e, fa); err != nil { - log.WithField("error", err).Fatal("sftp: failed to log event") + log.WithField("error", errors.WithStack(err)).WithField("event", e).Error("sftp: failed to log event") } }