Skip to content

Commit

Permalink
Merge pull request #374 from nyaruka/stop_writing_run_path
Browse files Browse the repository at this point in the history
Stop writing `flows_flowrun.path`
  • Loading branch information
rowanseymour authored Dec 10, 2024
2 parents 9d24ba8 + 5e7d1b1 commit e8004c0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
11 changes: 4 additions & 7 deletions core/models/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type FlowRun struct {
ExitedOn *time.Time `db:"exited_on"`
Responded bool `db:"responded"`
Results string `db:"results"`
Path string `db:"path"`
PathNodes pq.StringArray `db:"path_nodes"`
PathTimes pq.GenericArray `db:"path_times"`
CurrentNodeUUID null.String `db:"current_node_uuid"`
Expand Down Expand Up @@ -102,7 +101,6 @@ func newRun(ctx context.Context, tx *sqlx.Tx, oa *OrgAssets, session *Session, f
OrgID: oa.OrgID(),
SessionID: session.ID(),
StartID: NilStartID,
Path: string(jsonx.MustMarshal(path)),
PathNodes: pathNodes,
PathTimes: pq.GenericArray{A: pathTimes},
Results: string(jsonx.MustMarshal(fr.Results())),
Expand All @@ -127,9 +125,9 @@ func newRun(ctx context.Context, tx *sqlx.Tx, oa *OrgAssets, session *Session, f

const sqlInsertRun = `
INSERT INTO
flows_flowrun(uuid, created_on, modified_on, exited_on, status, responded, results, path, path_nodes, path_times,
flows_flowrun(uuid, created_on, modified_on, exited_on, status, responded, results, path_nodes, path_times,
current_node_uuid, contact_id, flow_id, org_id, session_id, start_id)
VALUES(:uuid, :created_on, NOW(), :exited_on, :status, :responded, :results, :path, :path_nodes, :path_times,
VALUES(:uuid, :created_on, NOW(), :exited_on, :status, :responded, :results, :path_nodes, :path_times,
:current_node_uuid, :contact_id, :flow_id, :org_id, :session_id, :start_id)
RETURNING id
`
Expand All @@ -149,15 +147,14 @@ SET
exited_on = r.exited_on::timestamptz,
responded = r.responded::bool,
results = r.results,
path = r.path::jsonb,
path_nodes = r.path_nodes::uuid[],
path_times = r.path_times::timestamptz[],
current_node_uuid = r.current_node_uuid::uuid,
modified_on = NOW()
FROM (
VALUES(:uuid, :status, :exited_on, :responded, :results, :path, :path_nodes, :path_times, :current_node_uuid)
VALUES(:uuid, :status, :exited_on, :responded, :results, :path_nodes, :path_times, :current_node_uuid)
) AS
r(uuid, status, exited_on, responded, results, path, path_nodes, path_times, current_node_uuid)
r(uuid, status, exited_on, responded, results, path_nodes, path_times, current_node_uuid)
WHERE
fr.uuid = r.uuid::uuid`

Expand Down
1 change: 0 additions & 1 deletion core/models/runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestInsertAndUpdateRuns(t *testing.T) {
ModifiedOn: t2,
Responded: true,
Results: `{}`,
Path: `[]`,
PathNodes: []string{"1895cae0-d3c0-4470-83df-0b4cf9449438", "3ea3c026-e1c0-4950-bb94-d4c532b1459f"},
PathTimes: pq.GenericArray{A: []interface{}{t1, t2}},
CurrentNodeUUID: "5f0d8d24-0178-4b10-ae35-b3ccdc785777",
Expand Down
4 changes: 2 additions & 2 deletions core/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestStartFlowBatch(t *testing.T) {
Returns(2)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE contact_id = ANY($1) and flow_id = $2 AND responded = FALSE AND org_id = 1 AND status = 'C'
AND results IS NOT NULL AND path IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID).
AND results IS NOT NULL AND path_nodes IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID).
Returns(2)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE contact_id = ANY($1) AND text = 'Hey, how are you?' AND org_id = 1 AND status = 'Q'
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestResume(t *testing.T) {

runQuery := `SELECT count(*) FROM flows_flowrun WHERE contact_id = $1 AND flow_id = $2
AND status = $3 AND responded = TRUE AND org_id = 1 AND current_node_uuid IS NOT NULL
AND json_array_length(path::json) = $4 AND session_id IS NOT NULL`
AND array_length(path_nodes, 1) = $4 AND session_id IS NOT NULL`

assertdb.Query(t, rt.DB, runQuery, modelContact.ID(), flow.ID(), tc.RunStatus, tc.PathLength).
Returns(1, "%d: didn't find expected run", i)
Expand Down
2 changes: 1 addition & 1 deletion core/tasks/starts/start_flow_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestStartFlowBatchTask(t *testing.T) {
Returns(2)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE contact_id = ANY($1) and flow_id = $2 AND responded = FALSE AND org_id = 1 AND status = 'C'
AND results IS NOT NULL AND path IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID).
AND results IS NOT NULL AND path_nodes IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID).
Returns(2)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE contact_id = ANY($1) AND text = 'Hey, how are you?' AND org_id = 1 AND status = 'Q'
Expand Down

0 comments on commit e8004c0

Please sign in to comment.