diff --git a/http/intersects.go b/http/intersects.go index 8d7a8fa..157a1d9 100644 --- a/http/intersects.go +++ b/http/intersects.go @@ -12,11 +12,11 @@ import ( pip_index "github.com/whosonfirst/go-whosonfirst-pip/index" pip_utils "github.com/whosonfirst/go-whosonfirst-pip/utils" "github.com/whosonfirst/go-whosonfirst-sqlite/database" - "log" + _ "log" gohttp "net/http" "strconv" "strings" - "sync" + _ "sync" ) type IntersectsHandlerOptions struct { @@ -203,63 +203,67 @@ func AppendExtras(js []byte, extras []string, places gjson.Result, db_path strin // TO DO: loop over places.Array() concurrently and reconstruct js from scratch // below, rather than trying to update it in place (20171219/thisisaaronland) - debug := js + /* + debug := js - type update struct { - Index int - Body []byte - } + type update struct { + Index int + Body []byte + } - done_ch := make(chan bool) - update_ch := make(chan update) + done_ch := make(chan bool) + update_ch := make(chan update) - rsp := gjson.GetBytes(debug, "places.#") - foo := rsp.Array() - - count := len(foo) + rsp := gjson.GetBytes(debug, "places.#") + foo := rsp.Array() - for i, rsp := range foo { + count := len(foo) - go func(idx int, rsp gjson.Result) { + for i, rsp := range foo { - defer func() { - done_ch <- true - }() + go func(idx int, rsp gjson.Result) { - pl := []byte(rsp.Raw) + defer func() { + done_ch <- true + }() - // update pl here... + pl := []byte(rsp.Raw) - up := update{ - Index: i, - Body: pl, - } + // update pl here... - update_ch <- up - }(i, rsp) + up := update{ + Index: i, + Body: pl, + } - // update pl here + update_ch <- up + }(i, rsp) - } + // update pl here - mu := new(sync.Mutex) - remaining := count + } - for remaining > 0 { + mu := new(sync.Mutex) + remaining := count - select { - case <-done_ch: - remaining -= 1 - case up := <-update_ch: + for remaining > 0 { - mu.Lock() - set_path := fmt.Sprintf("places.%d", up.Index) - debug, _ = sjson.SetBytes(debug, set_path, up.Body) - mu.Unlock() + select { + case <-done_ch: + remaining -= 1 + case up := <-update_ch: + + mu.Lock() + set_path := fmt.Sprintf("places.%d", up.Index) + log.Println("UPDATE", set_path, up.Body) + + debug, _ = sjson.SetBytes(debug, set_path, up.Body) + mu.Unlock() + } } - } - log.Println(string(debug)) + log.Println(string(debug)) + */ for i, id := range places.Array() { @@ -278,8 +282,6 @@ func AppendExtras(js []byte, extras []string, places gjson.Result, db_path strin switch { case err == sql.ErrNoRows: - // TO DO: determine if returning js, nil, false here is the cause of - // https://github.com/whosonfirst/go-whosonfirst-pip-v2/issues/16#issuecomment-352652505 continue case err != nil: return js, err, false @@ -328,8 +330,6 @@ func AppendExtras(js []byte, extras []string, places gjson.Result, db_path strin } } } - - break } return js, nil, true