Micro optimization

This commit is contained in:
Simon 2018-11-05 17:08:54 -05:00
parent add6581804
commit 1b5e6bb7f4

View File

@ -3,7 +3,6 @@ package main
import ( import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"math" "math"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -67,7 +66,7 @@ func (w WorkerContext) step(job Job) {
} }
func DoJob(job *Job, f *File) (newJobs []Job, err error) { func DoJob(job *Job, f *File) (newJobs []Job, err error) {
if strings.HasSuffix(job.Uri.Path, "/") { if job.Uri.Path[len(job.Uri.Path)-1] == '/' {
// Load directory // Load directory
links, err := GetDir(job, f) links, err := GetDir(job, f)
if err != nil { if err != nil {
@ -120,10 +119,10 @@ func (w WorkerContext) queueJob(job Job) {
globalWait.Add(1) globalWait.Add(1)
if w.numRateLimits > 0 { if w.numRateLimits > 0 {
if time.Since(w.lastRateLimit) > 5 * time.Second { if time.Since(w.lastRateLimit) > 5*time.Second {
w.numRateLimits = 0 w.numRateLimits = 0
} else { } else {
time.Sleep(time.Duration(math.Sqrt(float64(50 * w.numRateLimits))) * time.Sleep(time.Duration(math.Sqrt(float64(50*w.numRateLimits))) *
100 * time.Millisecond) 100 * time.Millisecond)
w.in <- job w.in <- job
} }