Skip to content

Commit

Permalink
Merge pull request #58 from nyaruka/remove_events
Browse files Browse the repository at this point in the history
No longer include events in run archives
  • Loading branch information
rowanseymour authored Jan 6, 2022
2 parents d875b55 + b6a3f97 commit cbaebfe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
16 changes: 8 additions & 8 deletions archives/archives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func TestCreateRunArchive(t *testing.T) {

// should have two record
assert.Equal(t, 2, task.RecordCount)
assert.Equal(t, int64(642), task.Size)
assert.Equal(t, "f793f863f5e060b9d67c5688a555da6a", task.Hash)
assert.Equal(t, int64(472), task.Size)
assert.Equal(t, "734d437e1c66d09e033d698c732178f8", task.Hash)
assertArchiveFile(t, task, "runs1.jsonl")

DeleteArchiveFile(task)
Expand All @@ -238,8 +238,8 @@ func TestCreateRunArchive(t *testing.T) {

// should have one record
assert.Equal(t, 1, task.RecordCount)
assert.Equal(t, int64(497), task.Size)
assert.Equal(t, "074de71dfb619c78dbac5b6709dd66c2", task.Hash)
assert.Equal(t, int64(490), task.Size)
assert.Equal(t, "c2138e3c3009a9c09fc55482903d93e4", task.Hash)
assertArchiveFile(t, task, "runs2.jsonl")

DeleteArchiveFile(task)
Expand Down Expand Up @@ -469,8 +469,8 @@ func TestArchiveOrgRuns(t *testing.T) {
assert.Equal(t, time.Date(2017, 8, 1, 0, 0, 0, 0, time.UTC), created[0].StartDate)
assert.Equal(t, MonthPeriod, created[0].Period)
assert.Equal(t, 1, created[0].RecordCount)
assert.Equal(t, int64(497), created[0].Size)
assert.Equal(t, "074de71dfb619c78dbac5b6709dd66c2", created[0].Hash)
assert.Equal(t, int64(490), created[0].Size)
assert.Equal(t, "c2138e3c3009a9c09fc55482903d93e4", created[0].Hash)

assert.Equal(t, time.Date(2017, 9, 1, 0, 0, 0, 0, time.UTC), created[1].StartDate)
assert.Equal(t, MonthPeriod, created[1].Period)
Expand All @@ -487,8 +487,8 @@ func TestArchiveOrgRuns(t *testing.T) {
assert.Equal(t, time.Date(2017, 10, 10, 0, 0, 0, 0, time.UTC), created[11].StartDate)
assert.Equal(t, DayPeriod, created[11].Period)
assert.Equal(t, 2, created[11].RecordCount)
assert.Equal(t, int64(2002), created[11].Size)
assert.Equal(t, "b75d6ee33ce26b786f1b341e875ecd62", created[11].Hash)
assert.Equal(t, int64(1984), created[11].Size)
assert.Equal(t, "869cc00ad4cca0371d07c88d8cf2bf26", created[11].Hash)

assert.Equal(t, 12, len(deleted))

Expand Down
10 changes: 2 additions & 8 deletions archives/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ FROM (
SELECT key, jsonb_build_object('name', value -> 'name', 'value', value -> 'value', 'input', value -> 'input', 'time', (value -> 'created_on')::text::timestamptz, 'category', value -> 'category', 'node', value -> 'node_uuid') as value
FROM jsonb_each(fr.results::jsonb)) AS values_data
) as values,
CASE
WHEN $1
THEN '[]'::jsonb
ELSE
coalesce(fr.events, '[]'::jsonb)
END AS events,
fr.created_on,
fr.modified_on,
fr.exited_on,
Expand All @@ -55,15 +49,15 @@ FROM (
JOIN LATERAL (SELECT uuid, name FROM flows_flow WHERE flows_flow.id = fr.flow_id) AS flow_struct ON True
JOIN LATERAL (SELECT uuid, name FROM contacts_contact cc WHERE cc.id = fr.contact_id) AS contact_struct ON True
WHERE fr.org_id = $2 AND fr.modified_on >= $3 AND fr.modified_on < $4
WHERE fr.org_id = $1 AND fr.modified_on >= $2 AND fr.modified_on < $3
ORDER BY fr.modified_on ASC, id ASC
) as rec;
`

// writeRunRecords writes the runs in the archive's date range to the passed in writer
func writeRunRecords(ctx context.Context, db *sqlx.DB, archive *Archive, writer *bufio.Writer) (int, error) {
var rows *sqlx.Rows
rows, err := db.QueryxContext(ctx, lookupFlowRuns, archive.Org.IsAnon, archive.Org.ID, archive.StartDate, archive.endDate())
rows, err := db.QueryxContext(ctx, lookupFlowRuns, archive.Org.ID, archive.StartDate, archive.endDate())
if err != nil {
return 0, errors.Wrapf(err, "error querying run records for org: %d", archive.Org.ID)
}
Expand Down
4 changes: 2 additions & 2 deletions archives/testdata/runs1.jsonl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"id":1,"uuid":"4ced1260-9cfe-4b7f-81dd-b637108f15b9","flow":{"uuid":"6639286a-9120-45d4-aa39-03ae3942a4a6","name":"Flow 1"},"contact":{"uuid":"3e814add-e614-41f7-8b5d-a07f670a698f","name":"Ajodinabiff Dane"},"responded":true,"path":[],"values":{},"events":[],"created_on":"2017-08-12T19:11:59.890662+00:00","modified_on":"2017-08-12T19:11:59.890662+00:00","exited_on":"2017-08-12T19:11:59.890662+00:00","exit_type":"completed","submitted_by":null}
{"id":2,"uuid":"7d68469c-0494-498a-bdf3-bac68321fd6d","flow":{"uuid":"6639286a-9120-45d4-aa39-03ae3942a4a6","name":"Flow 1"},"contact":{"uuid":"3e814add-e614-41f7-8b5d-a07f670a698f","name":"Ajodinabiff Dane"},"responded":true,"path":[{"node": "10896d63-8df7-4022-88dd-a9d93edf355b", "time": "2017-08-12T13:07:24.049815+00:00"}],"values":{"agree": {"name": "Do you agree?", "node": "a0434c54-3e26-4eb0-bafc-46cdeaf435ac", "time": "2017-05-03T12:25:21.714339+00:00", "input": "A", "value": "A", "category": "Strongly agree"}},"events":[{"msg": {"urn": "tel:+12076661212", "text": "hola", "uuid": "cf05c58f-31fb-4ce8-9e65-4ecc9fd47cbe", "channel": {"name": "1223", "uuid": "bbfe2e9c-cf69-4d0a-b42e-00ac3dc0b0b8"}}, "type": "msg_created", "step_uuid": "659cdae5-1f29-4a58-9437-10421f724268", "created_on": "2018-01-22T15:06:47.357682+00:00"}],"created_on":"2017-08-12T19:11:59.890662+00:00","modified_on":"2017-08-12T19:11:59.890662+00:00","exited_on":"2017-08-12T19:11:59.890662+00:00","exit_type":"completed","submitted_by":null}
{"id":1,"uuid":"4ced1260-9cfe-4b7f-81dd-b637108f15b9","flow":{"uuid":"6639286a-9120-45d4-aa39-03ae3942a4a6","name":"Flow 1"},"contact":{"uuid":"3e814add-e614-41f7-8b5d-a07f670a698f","name":"Ajodinabiff Dane"},"responded":true,"path":[],"values":{},"created_on":"2017-08-12T19:11:59.890662+00:00","modified_on":"2017-08-12T19:11:59.890662+00:00","exited_on":"2017-08-12T19:11:59.890662+00:00","exit_type":"completed","submitted_by":null}
{"id":2,"uuid":"7d68469c-0494-498a-bdf3-bac68321fd6d","flow":{"uuid":"6639286a-9120-45d4-aa39-03ae3942a4a6","name":"Flow 1"},"contact":{"uuid":"3e814add-e614-41f7-8b5d-a07f670a698f","name":"Ajodinabiff Dane"},"responded":true,"path":[{"node": "10896d63-8df7-4022-88dd-a9d93edf355b", "time": "2017-08-12T13:07:24.049815+00:00"}],"values":{"agree": {"name": "Do you agree?", "node": "a0434c54-3e26-4eb0-bafc-46cdeaf435ac", "time": "2017-05-03T12:25:21.714339+00:00", "input": "A", "value": "A", "category": "Strongly agree"}},"created_on":"2017-08-12T19:11:59.890662+00:00","modified_on":"2017-08-12T19:11:59.890662+00:00","exited_on":"2017-08-12T19:11:59.890662+00:00","exit_type":"completed","submitted_by":null}
2 changes: 1 addition & 1 deletion archives/testdata/runs2.jsonl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":3,"uuid":"de782b35-a398-46ed-8550-34c66053841b","flow":{"uuid":"629db399-a5fb-4fa0-88e6-f479957b63d2","name":"Flow 2"},"contact":{"uuid":"7051dff0-0a27-49d7-af1f-4494239139e6","name":"Joanne Stone"},"responded":true,"path":[{"node": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "time": "2017-08-12T13:07:24.049815+00:00"}],"values":{"agree": {"name": "Agree", "node": "084c8cf1-715d-4d0a-b38d-a616ed74e638", "time": "2017-05-03T12:25:21.714339+00:00", "input": "A", "value": "A", "category": "Strongly agree"}, "confirm_agree": {"name": "Do you agree?", "node": "a0434c54-3e26-4eb0-bafc-46cdeaf435ab", "time": "2017-05-03T12:25:21.714339+00:00", "input": "A", "value": "A", "category": "Confirmed Strongly agree"}},"events":[],"created_on":"2017-08-10T19:11:59.890662+00:00","modified_on":"2017-08-10T19:11:59.890662+00:00","exited_on":"2017-08-10T19:11:59.890662+00:00","exit_type":"completed","submitted_by":"greg@gmail.com"}
{"id":3,"uuid":"de782b35-a398-46ed-8550-34c66053841b","flow":{"uuid":"629db399-a5fb-4fa0-88e6-f479957b63d2","name":"Flow 2"},"contact":{"uuid":"7051dff0-0a27-49d7-af1f-4494239139e6","name":"Joanne Stone"},"responded":true,"path":[{"node": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "time": "2017-08-12T13:07:24.049815+00:00"}],"values":{"agree": {"name": "Agree", "node": "084c8cf1-715d-4d0a-b38d-a616ed74e638", "time": "2017-05-03T12:25:21.714339+00:00", "input": "A", "value": "A", "category": "Strongly agree"}, "confirm_agree": {"name": "Do you agree?", "node": "a0434c54-3e26-4eb0-bafc-46cdeaf435ab", "time": "2017-05-03T12:25:21.714339+00:00", "input": "A", "value": "A", "category": "Confirmed Strongly agree"}},"created_on":"2017-08-10T19:11:59.890662+00:00","modified_on":"2017-08-10T19:11:59.890662+00:00","exited_on":"2017-08-10T19:11:59.890662+00:00","exit_type":"completed","submitted_by":"greg@gmail.com"}

0 comments on commit cbaebfe

Please sign in to comment.