Skip to content

Commit

Permalink
Merge pull request #379 from nyaruka/new_msg_folder_counts
Browse files Browse the repository at this point in the history
Read outbox size check from new msg folder counts
  • Loading branch information
rowanseymour authored Dec 11, 2024
2 parents e84cd51 + 7fc4190 commit f75d358
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/models/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ SELECT ROW_TO_JSON(o) FROM (SELECT
GROUP BY c.country ORDER BY count(c.country) desc, country LIMIT 1
), ''
) AS default_country,
(SELECT SUM(count) FROM msgs_systemlabelcount WHERE org_id = $1 AND label_type = 'O') AS outbox_count
(SELECT SUM(count) FROM orgs_itemcount WHERE org_id = $1 AND scope = 'msgs:folder:O') AS outbox_count
FROM orgs_org o
WHERE id = $1
) o`
Expand Down
4 changes: 2 additions & 2 deletions core/tasks/starts/throttle_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestThrottleQueue(t *testing.T) {
assert.Equal(t, map[string]any{"paused": 0, "resumed": 1}, res)

// make it look like org 1 has 20,000 messages in its outbox
rt.DB.MustExec(`INSERT INTO msgs_systemlabelcount(org_id, label_type, count, is_squashed) VALUES (1, 'O', 10050, FALSE)`)
rt.DB.MustExec(`INSERT INTO orgs_itemcount(org_id, scope, count, is_squashed) VALUES (1, 'msgs:folder:O', 10050, FALSE)`)

models.FlushCache()

Expand All @@ -40,7 +40,7 @@ func TestThrottleQueue(t *testing.T) {
assert.Equal(t, map[string]any{"paused": 1, "resumed": 0}, res)

// make it look like most of the inbox has cleared
rt.DB.MustExec(`INSERT INTO msgs_systemlabelcount(org_id, label_type, count, is_squashed) VALUES (1, 'O', -10000, FALSE)`)
rt.DB.MustExec(`INSERT INTO orgs_itemcount(org_id, scope, count, is_squashed) VALUES (1, 'msgs:folder:O', -10000, FALSE)`)

models.FlushCache()

Expand Down
3 changes: 1 addition & 2 deletions testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ DELETE FROM channels_channelevent;
DELETE FROM channels_channellog;
DELETE FROM msgs_msg;
DELETE FROM flows_flowrun;
DELETE FROM flows_flowpathcount;
DELETE FROM flows_flowcategorycount;
DELETE FROM flows_flowactivitycount;
DELETE FROM flows_flowstartcount;
Expand All @@ -292,7 +291,6 @@ DELETE FROM flows_flowrevision WHERE flow_id >= 30000;
DELETE FROM flows_flow WHERE id >= 30000;
DELETE FROM ivr_call;
DELETE FROM campaigns_eventfire;
DELETE FROM msgs_systemlabelcount;
DELETE FROM msgs_msg_labels;
DELETE FROM msgs_msg;
DELETE FROM msgs_broadcast_groups;
Expand All @@ -312,6 +310,7 @@ DELETE FROM contacts_contactgroup_contacts WHERE contact_id >= 30000 OR contactg
DELETE FROM contacts_contact WHERE id >= 30000;
DELETE FROM contacts_contactgroupcount WHERE group_id >= 30000;
DELETE FROM contacts_contactgroup WHERE id >= 30000;
DELETE FROM orgs_itemcount;
ALTER SEQUENCE flows_flow_id_seq RESTART WITH 30000;
ALTER SEQUENCE tickets_ticket_id_seq RESTART WITH 1;
Expand Down

0 comments on commit f75d358

Please sign in to comment.