Move request building within loop to avoid shallow copy reuse between routines

This commit is contained in:
Alex D. 2023-06-08 13:34:14 +00:00
parent 6489774ca1
commit d8c691af3c
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 32 additions and 32 deletions

View File

@ -122,6 +122,7 @@ func Query(uname string, api_key string, tags []string, j_max Jobs, tout time.Du
res_chan := make(chan result)
var r_arr []result
for pid, rpid, ppid := Page(0), Page(0), Page(0); ; {
q := &http.Request{
URL: &url.URL{
Scheme: "https",
@ -139,7 +140,6 @@ func Query(uname string, api_key string, tags []string, j_max Jobs, tout time.Du
}
q.URL.RawQuery = uq.Encode()
for pid, rpid, ppid := Page(0), Page(0), Page(0); ; {
go run_job(q, tout, pid, res_chan)
pid++

View File

@ -82,6 +82,7 @@ func Query(tags Tags, j_max Jobs) (mr []Media, err error) {
res_chan := make(chan result)
var r_arr []result
for pid, rpid, ppid := uint(0), uint(0), uint(0); ; {
q := &http.Request{
URL: &url.URL{
Scheme: "https",
@ -97,7 +98,6 @@ func Query(tags Tags, j_max Jobs) (mr []Media, err error) {
qu.Set("tags", strings.Join(tags, " "))
q.URL.RawQuery = qu.Encode()
for pid, rpid, ppid := uint(0), uint(0), uint(0); ; {
if pid <= 200 { // API only allows to fetch up to 200 pages per query
go run_job(q, pid, res_chan)
pid++