Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Make metainfo_fetcher fetch metadata only for new torrents (#694)

Added a flag on the config, that, when set, will only fetch data starting
from torrents with ID > config.LastOldTorrentID. Also updated the query
to use the config's files table, instead of hard-coding it.
Cette révision appartient à :
Ramon Dantas 2017-05-22 22:19:28 -03:00 révisé par ewhal
Parent 2e7392f46e
révision 38f331a32e
2 fichiers modifiés avec 29 ajouts et 7 suppressions

Voir le fichier

@ -10,6 +10,8 @@ type MetainfoFetcherConfig struct {
UploadRateLimiter int `json:"upload_rate_limiter"` UploadRateLimiter int `json:"upload_rate_limiter"`
DownloadRateLimiter int `json:"download_rate_limiter"` DownloadRateLimiter int `json:"download_rate_limiter"`
FetchNewTorrentsOnly bool `json:"fetch_new_torrents_only"`
} }
var DefaultMetainfoFetcherConfig = MetainfoFetcherConfig{ var DefaultMetainfoFetcherConfig = MetainfoFetcherConfig{
@ -22,5 +24,6 @@ var DefaultMetainfoFetcherConfig = MetainfoFetcherConfig{
UploadRateLimiter: 1024, // kbps UploadRateLimiter: 1024, // kbps
DownloadRateLimiter: 1024, DownloadRateLimiter: 1024,
FetchNewTorrentsOnly: true, // Only fetch torrents newer than config.LastOldTorrentID
} }

Voir le fichier

@ -23,6 +23,7 @@ type MetainfoFetcher struct {
maxDays int maxDays int
baseFailCooldown int baseFailCooldown int
maxFailCooldown int maxFailCooldown int
newTorrentsOnly bool
done chan int done chan int
queue []*FetchOperation queue []*FetchOperation
queueMutex sync.Mutex queueMutex sync.Mutex
@ -52,6 +53,7 @@ func New(fetcherConfig *config.MetainfoFetcherConfig) (fetcher *MetainfoFetcher,
queueSize: fetcherConfig.QueueSize, queueSize: fetcherConfig.QueueSize,
timeout: fetcherConfig.Timeout, timeout: fetcherConfig.Timeout,
maxDays: fetcherConfig.MaxDays, maxDays: fetcherConfig.MaxDays,
newTorrentsOnly: fetcherConfig.FetchNewTorrentsOnly,
baseFailCooldown: fetcherConfig.BaseFailCooldown, baseFailCooldown: fetcherConfig.BaseFailCooldown,
maxFailCooldown: fetcherConfig.MaxFailCooldown, maxFailCooldown: fetcherConfig.MaxFailCooldown,
done: make(chan int, 1), done: make(chan int, 1),
@ -227,16 +229,32 @@ func (fetcher *MetainfoFetcher) fillQueue() {
for id, _ := range fetcher.failedOperations { for id, _ := range fetcher.failedOperations {
excludedIDS = append(excludedIDS, id) excludedIDS = append(excludedIDS, id)
} }
tFiles := config.FilesTableName
tTorrents := config.TorrentsTableName
// Select the torrents with no filesize, or without any rows with torrent_id in the files table...
queryString := "((filesize IS NULL OR filesize = 0) OR ("+tTorrents+".torrent_id NOT "+
"IN (SELECT "+tFiles+".torrent_id FROM "+tFiles+" WHERE "+tFiles+
".torrent_id = "+tTorrents+".torrent_id)))"
var whereParamsArgs []interface{}
// Nice query lol // that are newer than maxDays...
// Select the torrents with no filesize, or without any rows with torrent_id in the files table, that are younger than fetcher.MaxDays queryString += " AND date > ? "
var params serviceBase.WhereParams whereParamsArgs = append(whereParamsArgs, oldest)
// that didn't fail recently...
if len(excludedIDS) > 0 { if len(excludedIDS) > 0 {
params = serviceBase.CreateWhereParams("((filesize IS NULL OR filesize = 0) OR ("+config.TorrentsTableName+".torrent_id NOT IN (SELECT files.torrent_id FROM files WHERE files.torrent_id = "+config.TorrentsTableName+".torrent_id))) AND date > ? AND torrent_id NOT IN (?)", oldest, excludedIDS) queryString += " AND torrent_id NOT IN (?) "
} else { whereParamsArgs = append(whereParamsArgs, excludedIDS)
params = serviceBase.CreateWhereParams("((filesize IS NULL OR filesize = 0) OR ("+config.TorrentsTableName+".torrent_id NOT IN (SELECT files.torrent_id FROM files WHERE files.torrent_id = "+config.TorrentsTableName+".torrent_id))) AND date > ?", oldest)
} }
// and, if true, that aren't from the old Nyaa database
if fetcher.newTorrentsOnly {
queryString += " AND torrent_id > ? "
whereParamsArgs = append(whereParamsArgs, config.LastOldTorrentID)
}
params := serviceBase.CreateWhereParams(queryString, whereParamsArgs...)
dbTorrents, err := torrentService.GetTorrentsOrderByNoCount(&params, "", fetcher.queueSize, 0) dbTorrents, err := torrentService.GetTorrentsOrderByNoCount(&params, "", fetcher.queueSize, 0)
if len(dbTorrents) == 0 { if len(dbTorrents) == 0 {
@ -271,17 +289,18 @@ func (fetcher *MetainfoFetcher) run() {
defer fetcher.wg.Done() defer fetcher.wg.Done()
done := 0 done := 0
fetcher.fillQueue()
for done == 0 { for done == 0 {
fetcher.removeOldFailures() fetcher.removeOldFailures()
fetcher.fillQueue() fetcher.fillQueue()
select { select {
case done = <-fetcher.done: case done = <-fetcher.done:
log.Infof("Got done signal on main loop, leaving...")
break break
case result = <-fetcher.results: case result = <-fetcher.results:
fetcher.gotResult(result) fetcher.gotResult(result)
break break
case <-fetcher.wakeUp.C: case <-fetcher.wakeUp.C:
log.Infof("Got wake up signal...")
break break
} }
} }