mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-26 23:53:21 +03:00
Merge pull request #542 from nicois/nicois/use-prepared-statement-for-bulk-writes
Use prepared statement for bulk writes
This commit is contained in:
commit
40aadbad85
@ -258,12 +258,23 @@ func (c *messageCache) addMessages(ms []*message) error {
|
||||
if c.nop {
|
||||
return nil
|
||||
}
|
||||
if len(ms) == 0 {
|
||||
return nil
|
||||
}
|
||||
start := time.Now()
|
||||
tx, err := c.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
statement, err := tx.Prepare(
|
||||
insertMessageQuery,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer statement.Close()
|
||||
|
||||
for _, m := range ms {
|
||||
if m.Event != messageEvent {
|
||||
return errUnexpectedMessageType
|
||||
@ -291,8 +302,7 @@ func (c *messageCache) addMessages(ms []*message) error {
|
||||
if m.Sender.IsValid() {
|
||||
sender = m.Sender.String()
|
||||
}
|
||||
_, err := tx.Exec(
|
||||
insertMessageQuery,
|
||||
_, err := statement.Exec(
|
||||
m.ID,
|
||||
m.Time,
|
||||
m.Topic,
|
||||
|
Loading…
Reference in New Issue
Block a user