From 09d1a57a87d444c475906cae417fe7d3ee9d8df5 Mon Sep 17 00:00:00 2001 From: "Bora M. Alper" Date: Tue, 15 Aug 2017 18:14:47 +0300 Subject: [PATCH] a more sensible buffer (10) for newTorrents and add &then flush --- src/magneticod/persistence.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/magneticod/persistence.go b/src/magneticod/persistence.go index d5c5f5f..208714d 100644 --- a/src/magneticod/persistence.go +++ b/src/magneticod/persistence.go @@ -77,7 +77,9 @@ func NewDatabase(rawurl string) (*Database, error) { // AddNewTorrent adds a new torrent to the *queue* to be flushed to the persistent database. func (db *Database) AddNewTorrent(torrent bittorrent.Metadata) error { - if len(db.newTorrents) >= 1 { + db.newTorrents = append(db.newTorrents, torrent) + + if len(db.newTorrents) >= 10 { zap.L().Sugar().Debugf("newTorrents queue is full, attempting to commit %d torrents...", len(db.newTorrents)) if err := db.commitNewTorrents(); err != nil { @@ -85,7 +87,6 @@ func (db *Database) AddNewTorrent(torrent bittorrent.Metadata) error { } } - db.newTorrents = append(db.newTorrents, torrent) return nil }