Support more rapid insertion; ignore issues with i/o

This commit is contained in:
DaneEveritt 2022-07-24 16:58:03 -04:00
parent 8cee18a92b
commit c18e844689
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 8 additions and 2 deletions

View File

@ -35,6 +35,12 @@ func Initialize() error {
sql.SetMaxOpenConns(1) sql.SetMaxOpenConns(1)
sql.SetConnMaxLifetime(time.Hour) 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 { if err := db.AutoMigrate(&models.Activity{}); err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }

View File

@ -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 { 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 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. // if an error is encountered during the logging of the event.
func (eh *eventHandler) MustLog(e models.Event, fa FileAction) { func (eh *eventHandler) MustLog(e models.Event, fa FileAction) {
if err := eh.Log(e, fa); err != nil { 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")
} }
} }