fix duplicate torrents (again)
This commit is contained in:
12
main.go
12
main.go
@@ -112,16 +112,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guidTorrent, _ := m.GetTorrentByGuid(torrent.Guid)
|
guidTorrent, _ := m.GetTorrentByGuidAndItemId(torrent.Guid, item.ID)
|
||||||
if guidTorrent != nil {
|
if guidTorrent != nil {
|
||||||
_, err = db.NamedExec("UPDATE torrents SET seeders = :seeders, peers = :peers WHERE guid = :guid", map[string]any{
|
// already have this exact one, for this item. ABORT!
|
||||||
"seeders": seeders,
|
continue
|
||||||
"peers": peers,
|
|
||||||
"guid": torrent.Guid,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("couldn't update seers & peers for torrent guid=%s: %v\n", torrent.Guid, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this shit will duplicate. idk if it's ok or not, but fuck it. we ball
|
// this shit will duplicate. idk if it's ok or not, but fuck it. we ball
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ func (m *Model) GetTorrentById(torrentId int64) (*Torrent, error) {
|
|||||||
return torrent, nil
|
return torrent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) GetTorrentByGuid(guid string) (*Torrent, error) {
|
func (m *Model) GetTorrentByGuidAndItemId(guid string, itemId int64) (*Torrent, error) {
|
||||||
torrent := new(Torrent)
|
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 {
|
if err := row.StructScan(torrent); err != nil {
|
||||||
return nil, fmt.Errorf("torrent not found: %v", err)
|
return nil, fmt.Errorf("torrent not found: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user