Skip to content

Commit

Permalink
Don't include status groups in contact indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 8, 2024
1 parent b78b579 commit 33483fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion indexers/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
) AS f
) AS fields,
(
SELECT array_to_json(array_agg(gc.contactgroup_id)) FROM contacts_contactgroup_contacts gc WHERE gc.contact_id = contacts_contact.id
SELECT array_to_json(array_agg(gc.contactgroup_id))
FROM contacts_contactgroup_contacts gc
INNER JOIN contacts_contactgroup g ON g.id = gc.contactgroup_id
WHERE gc.contact_id = contacts_contact.id AND g.group_type IN ('M', 'Q')
) AS group_ids,
current_flow_id AS flow_id,
(
Expand Down
3 changes: 2 additions & 1 deletion indexers/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ var contactQueryTests = []struct {
{elastic.Match("group_ids", 1), []int64{1}},
{elastic.Match("group_ids", 4), []int64{1, 2}},
{elastic.Match("group_ids", 2), []int64{}},
{elastic.Match("group_ids", 5), []int64{}}, // wrong group type
}

func TestContacts(t *testing.T) {
Expand Down Expand Up @@ -202,7 +203,7 @@ func TestContacts(t *testing.T) {

// now make some contact changes, removing one contact, updating another
_, err = db.Exec(`
DELETE FROM contacts_contactgroup_contacts WHERE id = 3;
DELETE FROM contacts_contactgroup_contacts WHERE contact_id = 2 AND contactgroup_id = 4;
UPDATE contacts_contact SET name = 'John Deer', modified_on = '2020-08-20 14:00:00+00' where id = 2;
UPDATE contacts_contact SET is_active = FALSE, modified_on = '2020-08-22 15:00:00+00' where id = 4;`)
require.NoError(t, err)
Expand Down
18 changes: 11 additions & 7 deletions testdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ DROP TABLE IF EXISTS contacts_contactgroup CASCADE;
CREATE TABLE contacts_contactgroup (
id SERIAL PRIMARY KEY,
uuid character varying(36) NOT NULL,
name character varying(128) NOT NULL
name character varying(128) NOT NULL,
group_type character varying(1) NOT NULL
);

DROP TABLE IF EXISTS contacts_contactgroup_contacts CASCADE;
Expand Down Expand Up @@ -151,16 +152,19 @@ INSERT INTO contacts_contacturn(id, contact_id, scheme, org_id, priority, path,
(10, 9, 'twitterid', 2, 90, 1000001, 'fungal', 'twitterid:1000001'),
(11, 10, 'whatsapp', 2, 90, 1000003, NULL, 'whatsapp:1000003');

INSERT INTO contacts_contactgroup(id, uuid, name) VALUES
(1, '4ea0f313-2f62-4e57-bdf0-232b5191dd57', 'Group 1'),
(2, '4c016340-468d-4675-a974-15cb7a45a5ab', 'Group 2'),
(3, 'e61b5bf7-8ddf-4e05-b0a8-4c46a6b68cff', 'Group 3'),
(4, '529bac39-550a-4d6f-817c-1833f3449007', 'Group 4');
INSERT INTO contacts_contactgroup(id, uuid, name, group_type) VALUES
(1, '4ea0f313-2f62-4e57-bdf0-232b5191dd57', 'Group 1', 'Q'),
(2, '4c016340-468d-4675-a974-15cb7a45a5ab', 'Group 2', 'M'),
(3, 'e61b5bf7-8ddf-4e05-b0a8-4c46a6b68cff', 'Group 3', 'Q'),
(4, '529bac39-550a-4d6f-817c-1833f3449007', 'Group 4', 'M'),
(5, '004c982b-859e-4e7b-9c30-e38c0e6b6537', 'Active', 'A');

INSERT INTO contacts_contactgroup_contacts(id, contact_id, contactgroup_id) VALUES
(1, 1, 1),
(2, 1, 4),
(3, 2, 4);
(3, 1, 5),
(4, 2, 4),
(5, 2, 5);

INSERT INTO flows_flowrun(id, uuid, flow_id, contact_id) VALUES
(1, '8b30ee61-e19d-427e-bb9f-4b8cd2c31d0c', 1, 1),
Expand Down

0 comments on commit 33483fd

Please sign in to comment.