Skip to content

Commit 33483fd

Browse files
committed
Don't include status groups in contact indexing
1 parent b78b579 commit 33483fd

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

indexers/contacts.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
136136
) AS f
137137
) AS fields,
138138
(
139-
SELECT array_to_json(array_agg(gc.contactgroup_id)) FROM contacts_contactgroup_contacts gc WHERE gc.contact_id = contacts_contact.id
139+
SELECT array_to_json(array_agg(gc.contactgroup_id))
140+
FROM contacts_contactgroup_contacts gc
141+
INNER JOIN contacts_contactgroup g ON g.id = gc.contactgroup_id
142+
WHERE gc.contact_id = contacts_contact.id AND g.group_type IN ('M', 'Q')
140143
) AS group_ids,
141144
current_flow_id AS flow_id,
142145
(

indexers/contacts_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ var contactQueryTests = []struct {
161161
{elastic.Match("group_ids", 1), []int64{1}},
162162
{elastic.Match("group_ids", 4), []int64{1, 2}},
163163
{elastic.Match("group_ids", 2), []int64{}},
164+
{elastic.Match("group_ids", 5), []int64{}}, // wrong group type
164165
}
165166

166167
func TestContacts(t *testing.T) {
@@ -202,7 +203,7 @@ func TestContacts(t *testing.T) {
202203

203204
// now make some contact changes, removing one contact, updating another
204205
_, err = db.Exec(`
205-
DELETE FROM contacts_contactgroup_contacts WHERE id = 3;
206+
DELETE FROM contacts_contactgroup_contacts WHERE contact_id = 2 AND contactgroup_id = 4;
206207
UPDATE contacts_contact SET name = 'John Deer', modified_on = '2020-08-20 14:00:00+00' where id = 2;
207208
UPDATE contacts_contact SET is_active = FALSE, modified_on = '2020-08-22 15:00:00+00' where id = 4;`)
208209
require.NoError(t, err)

testdb.sql

+11-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ DROP TABLE IF EXISTS contacts_contactgroup CASCADE;
4242
CREATE TABLE contacts_contactgroup (
4343
id SERIAL PRIMARY KEY,
4444
uuid character varying(36) NOT NULL,
45-
name character varying(128) NOT NULL
45+
name character varying(128) NOT NULL,
46+
group_type character varying(1) NOT NULL
4647
);
4748

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

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

160162
INSERT INTO contacts_contactgroup_contacts(id, contact_id, contactgroup_id) VALUES
161163
(1, 1, 1),
162164
(2, 1, 4),
163-
(3, 2, 4);
165+
(3, 1, 5),
166+
(4, 2, 4),
167+
(5, 2, 5);
164168

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

0 commit comments

Comments
 (0)