fix: fix the error of database is locked when use sqlite (#60)

This commit is contained in:
Li4n0
2022-09-14 01:08:42 +08:00
committed by GitHub
parent 3fa2cae862
commit d29b767d9c
7 changed files with 49 additions and 2 deletions
+7
View File
@@ -44,6 +44,13 @@ func NewRecord(rule *Rule, flag, method, url, ip, area, raw string) (r *Record,
RawRequest: raw,
Rule: *rule,
}
// sqlite db-level lock to prevent too much write operation lead to error of `database is locked` #54
if database.Driver == database.Sqlite {
database.Locker.Lock()
defer database.Locker.Unlock()
}
return r, database.DB.Create(r).Error
}