|
|
@ -27,10 +27,16 @@ func main() {
|
|
|
|
for _, torrent := range torrents {
|
|
|
|
for _, torrent := range torrents {
|
|
|
|
addTorrent(db, torrent, &crawled)
|
|
|
|
addTorrent(db, torrent, &crawled)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
time.Sleep(time.Minute * 30)
|
|
|
|
time.Sleep(time.Minute * 45)
|
|
|
|
|
|
|
|
go refresh(db)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func refresh(db *sql.DB) {
|
|
|
|
|
|
|
|
db.Exec("REFRESH MATERIALIZED VIEW fresh")
|
|
|
|
|
|
|
|
db.Exec("REFRESH MATERIALIZED VIEW CONCURRENTLY search")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func addTorrent(db *sql.DB, torr Torrent, crawled *map[string]bool) {
|
|
|
|
func addTorrent(db *sql.DB, torr Torrent, crawled *map[string]bool) {
|
|
|
|
if !(*crawled)[string(torr.Infohash)] {
|
|
|
|
if !(*crawled)[string(torr.Infohash)] {
|
|
|
|
_, err := db.Exec("INSERT INTO torrent (infohash, name, length) VALUES ($1, $2, $3)", torr.Infohash, torr.Name, torr.Length)
|
|
|
|
_, err := db.Exec("INSERT INTO torrent (infohash, name, length) VALUES ($1, $2, $3)", torr.Infohash, torr.Name, torr.Length)
|
|
|
|