Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
fix bug where we were only appending the first record per issue #19; …
Browse files Browse the repository at this point in the history
…stub out code to do updates concurrently
  • Loading branch information
thisisaaroland committed Dec 19, 2017
1 parent 4a1762f commit 1115646
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions http/intersects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {

Expand All @@ -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
Expand Down Expand Up @@ -328,8 +330,6 @@ func AppendExtras(js []byte, extras []string, places gjson.Result, db_path strin
}
}
}

break
}

return js, nil, true
Expand Down

0 comments on commit 1115646

Please sign in to comment.