From 13b132f5f06753c51a1265ddeef27ad3dafa12ac Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Tue, 3 Feb 2026 18:47:10 +0300 Subject: [PATCH] fix duplicate torrents (again) --- main.go | 12 +++--------- model/torrents.go | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 0764b45..f67d543 100644 --- a/main.go +++ b/main.go @@ -112,16 +112,10 @@ func main() { } } - guidTorrent, _ := m.GetTorrentByGuid(torrent.Guid) + guidTorrent, _ := m.GetTorrentByGuidAndItemId(torrent.Guid, item.ID) if guidTorrent != nil { - _, err = db.NamedExec("UPDATE torrents SET seeders = :seeders, peers = :peers WHERE guid = :guid", map[string]any{ - "seeders": seeders, - "peers": peers, - "guid": torrent.Guid, - }) - if err != nil { - log.Printf("couldn't update seers & peers for torrent guid=%s: %v\n", torrent.Guid, err) - } + // already have this exact one, for this item. ABORT! + continue } // this shit will duplicate. idk if it's ok or not, but fuck it. we ball diff --git a/model/torrents.go b/model/torrents.go index be754ae..f418ebf 100644 --- a/model/torrents.go +++ b/model/torrents.go @@ -31,10 +31,10 @@ func (m *Model) GetTorrentById(torrentId int64) (*Torrent, error) { return torrent, nil } -func (m *Model) GetTorrentByGuid(guid string) (*Torrent, error) { +func (m *Model) GetTorrentByGuidAndItemId(guid string, itemId int64) (*Torrent, error) { torrent := new(Torrent) - row := m.db.QueryRowx("SELECT * FROM torrents WHERE guid = ?", guid) + row := m.db.QueryRowx("SELECT * FROM torrents WHERE guid = ? AND item_id = ?", guid, itemId) if err := row.StructScan(torrent); err != nil { return nil, fmt.Errorf("torrent not found: %v", err) }