fix duplicate torrents (again)

This commit is contained in:
2026-02-03 18:47:10 +03:00
parent 82b0c567fe
commit 13b132f5f0
2 changed files with 5 additions and 11 deletions

12
main.go
View File

@@ -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

View File

@@ -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)
}