diff --git a/internal/api.go b/internal/api.go index 21ae375..9099768 100644 --- a/internal/api.go +++ b/internal/api.go @@ -125,7 +125,7 @@ func API() { if busy { c.String(http.StatusConflict, "busy") } else { - go DownloadProxies() + go DownloadInit() c.String(http.StatusOK, "ok") } }) diff --git a/internal/db.go b/internal/db.go index 2765040..badcb01 100644 --- a/internal/db.go +++ b/internal/db.go @@ -158,23 +158,29 @@ func dbCacheStats() { //-------------------------------------------------------------------------------------- func loadDb(proxy *Proxy) { + defer mutex.Unlock() _, err := DB.Exec(`insert into proxies("created_at", "updated_at", "check_count", "country", "fail_count", "last_status", "proxy", "timeout_count", "source", "success_count", "anonymous", "losing_streak") VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12) ON CONFLICT (proxy) DO UPDATE SET updated_at = EXCLUDED.updated_at `, time.Now(), time.Now(), proxy.CheckCount, proxy.Country, proxy.FailCount, proxy.LastStatus, proxy.Proxy, proxy.TimeoutCount, proxy.Source, proxy.SuccessCount, proxy.Anonymous, proxy.LosingStreak) + mutex.Lock() if err != nil { log.Fatal(err) } } func dbInsert(proxy *Proxy) { + defer mutex.Unlock() + _, err := DB.Exec(`update proxies SET "updated_at" = $1, "check_count" = $2 ,"fail_count" = $3, "last_status" = $4, "timeout_count" = $5, "success_count" = $6, "losing_streak" = $7, "deleted" = $8, "anonymous" = $9 , "proxy" = $10, judge = $11, "resp_time" = $12 where id = $13`, time.Now(), proxy.CheckCount, proxy.FailCount, proxy.LastStatus, proxy.TimeoutCount, proxy.SuccessCount, proxy.LosingStreak, proxy.Deleted, proxy.Anonymous, proxy.Proxy, proxy.Judge, proxy.RespTime, proxy.ID) + mutex.Lock() + if err != nil { log.Println(err) } diff --git a/internal/providers.go b/internal/providers.go index f3b1d8a..7f19ca8 100644 --- a/internal/providers.go +++ b/internal/providers.go @@ -708,6 +708,7 @@ func proxylistDownloadP(ctx context.Context) Proxies { start := time.Now() var ( foundProxies Proxies + mu sync.Mutex source = "proxy-list.download" urls = []string{ "https://www.proxy-list.download/api/v1/get?type=http", @@ -728,7 +729,9 @@ func proxylistDownloadP(ctx context.Context) Proxies { continue } p := Proxy{Proxy: proxy, Source: source} + mu.Unlock() foundProxies = append(foundProxies, &p) + mu.Unlock() } done <- true }