Skip to content

Commit

Permalink
Merge pull request #299 from nyaruka/latest_goflow
Browse files Browse the repository at this point in the history
Update to latest goflow v0.92.0
  • Loading branch information
rowanseymour authored Jun 16, 2020
2 parents 9f700d7 + 4fbb015 commit 022c573
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 2,408 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ require (
github.com/jmoiron/sqlx v1.2.0
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lib/pq v1.4.0
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.2.0
github.com/nyaruka/goflow v0.91.1
github.com/nyaruka/goflow v0.92.0
github.com/nyaruka/librato v1.0.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
github.com/olivere/elastic v6.2.30+incompatible
github.com/olivere/elastic v6.2.33+incompatible
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_model v0.2.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.4.0 h1:TmtCFbH+Aw0AixwyttznSMQDgbR5Yed/Gg6S8Funrhc=
github.com/lib/pq v1.4.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8=
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
Expand All @@ -128,8 +128,8 @@ github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0=
github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw=
github.com/nyaruka/gocommon v1.2.0 h1:gCmVCXYZFwKDMqQj8R1jNlK+7a06khKFq3zX8fBBbzw=
github.com/nyaruka/gocommon v1.2.0/go.mod h1:9Y21Fd6iZXDLHWTRiZAc6b4LQSCi6HEEQK4SB45Yav4=
github.com/nyaruka/goflow v0.91.1 h1:TJ3SkbkCh5Wk5U2myGgg0uhUbgacdefBvlb6hDOuABc=
github.com/nyaruka/goflow v0.91.1/go.mod h1:HBoTXbhrjhZENbCUlDvh8ZCR16ZvlgY4aTE/ABMS8uE=
github.com/nyaruka/goflow v0.92.0 h1:6eS5RN0kgEhafzJsfhKOAkk+tecQAo6yImaxmy56Sog=
github.com/nyaruka/goflow v0.92.0/go.mod h1:PDah2hr5WzODnUFK4VWWQkg7SqnYclf7P9Ik5u/VOG0=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg=
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d h1:hyp9u36KIwbTCo2JAJ+TuJcJBc+UZzEig7RI/S5Dvkc=
Expand All @@ -139,8 +139,8 @@ github.com/nyaruka/null v1.2.0/go.mod h1:HSAFbLNOaEhHnoU0VCveCPz0GDtJ3GEtFWhvnBN
github.com/nyaruka/phonenumbers v1.0.34/go.mod h1:GQ0cTHlrxPrhoLwyQ1blyN1hO794ygt6FTHWrFB5SSc=
github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg=
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
github.com/olivere/elastic v6.2.30+incompatible h1:9JdhoNFfUF809qM1S5WLz3CZaxazd/mDty9XXwDRz4Q=
github.com/olivere/elastic v6.2.30+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
github.com/olivere/elastic v6.2.33+incompatible h1:SRPB2w2OhJ7iULftDEHsNPRoL2GLREqPMRalVmbZaEw=
github.com/olivere/elastic v6.2.33+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
Expand Down
12 changes: 7 additions & 5 deletions models/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/contactql"
"github.com/nyaruka/goflow/contactql/es"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/excellent/types"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/goflow/utils/uuids"
"github.com/nyaruka/mailroom/search"
"github.com/nyaruka/null"
"github.com/olivere/elastic"

Expand Down Expand Up @@ -198,7 +198,7 @@ func BuildElasticQuery(org *OrgAssets, group assets.GroupUUID, query *contactql.

// and by our query if present
if query != nil {
q, err := search.ToElasticQuery(org.Env(), org.SessionAssets(), query)
q, err := es.ToElasticQuery(org.Env(), org.SessionAssets(), query)
if err != nil {
return nil, errors.Wrapf(err, "error converting contactql to elastic query: %s", query)
}
Expand All @@ -211,6 +211,7 @@ func BuildElasticQuery(org *OrgAssets, group assets.GroupUUID, query *contactql.

// ContactIDsForQueryPage returns the ids of the contacts for the passed in query page
func ContactIDsForQueryPage(ctx context.Context, client *elastic.Client, org *OrgAssets, group assets.GroupUUID, query string, sort string, offset int, pageSize int) (*contactql.ContactQuery, []ContactID, int64, error) {
env := org.Env()
start := time.Now()
var parsed *contactql.ContactQuery
var err error
Expand All @@ -220,7 +221,7 @@ func ContactIDsForQueryPage(ctx context.Context, client *elastic.Client, org *Or
}

if query != "" {
parsed, err = search.ParseQuery(org.Env(), org.SessionAssets(), query)
parsed, err = contactql.ParseQuery(query, env.RedactionPolicy(), env.DefaultCountry(), org.SessionAssets())
if err != nil {
return nil, nil, 0, errors.Wrapf(err, "error parsing query: %s", query)
}
Expand All @@ -231,7 +232,7 @@ func ContactIDsForQueryPage(ctx context.Context, client *elastic.Client, org *Or
return nil, nil, 0, errors.Wrapf(err, "error parsing query: %s", query)
}

fieldSort, err := search.ToElasticFieldSort(org.SessionAssets(), sort)
fieldSort, err := es.ToElasticFieldSort(org.SessionAssets(), sort)
if err != nil {
return nil, nil, 0, errors.Wrapf(err, "error parsing sort")
}
Expand Down Expand Up @@ -274,14 +275,15 @@ func ContactIDsForQueryPage(ctx context.Context, client *elastic.Client, org *Or

// ContactIDsForQuery returns the ids of all the contacts that match the passed in query
func ContactIDsForQuery(ctx context.Context, client *elastic.Client, org *OrgAssets, query string) ([]ContactID, error) {
env := org.Env()
start := time.Now()

if client == nil {
return nil, errors.Errorf("no elastic client available, check your configuration")
}

// turn into elastic query
parsed, err := search.ParseQuery(org.Env(), org.SessionAssets(), query)
parsed, err := contactql.ParseQuery(query, env.RedactionPolicy(), env.DefaultCountry(), org.SessionAssets())
if err != nil {
return nil, errors.Wrapf(err, "error parsing query: %s", query)
}
Expand Down
7 changes: 3 additions & 4 deletions models/contacts_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package models

import (
"fmt"
"testing"

"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/mailroom/search"
"github.com/nyaruka/mailroom/testsuite"

"github.com/olivere/elastic"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"

"fmt"
)

func TestElasticContacts(t *testing.T) {
testsuite.Reset()
ctx := testsuite.CTX()
db := testsuite.DB()

es := search.NewMockElasticServer()
es := testsuite.NewMockElasticServer()
defer es.Close()

client, err := elastic.NewClient(
Expand Down
6 changes: 3 additions & 3 deletions models/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"testing"

"github.com/lib/pq"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/utils/uuids"
"github.com/nyaruka/mailroom/search"
"github.com/nyaruka/mailroom/testsuite"

"github.com/lib/pq"
"github.com/olivere/elastic"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestDynamicGroups(t *testing.T) {
org, err := GetOrgAssets(ctx, db, Org1)
assert.NoError(t, err)

esServer := search.NewMockElasticServer()
esServer := testsuite.NewMockElasticServer()
defer esServer.Close()

es, err := elastic.NewClient(
Expand Down
Loading

0 comments on commit 022c573

Please sign in to comment.