From 4a64fb16d9ac9c642aed4a53e85ba0f5735720cd Mon Sep 17 00:00:00 2001 From: Kathy Nguyen Date: Wed, 31 Jan 2024 12:38:11 -0500 Subject: [PATCH 1/3] Add assignment load limit --- docs/REFERENCE-environment_variables.md | 1 + src/server/api/assignment.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/docs/REFERENCE-environment_variables.md b/docs/REFERENCE-environment_variables.md index 994544d15..4712a0c3c 100644 --- a/docs/REFERENCE-environment_variables.md +++ b/docs/REFERENCE-environment_variables.md @@ -6,6 +6,7 @@ | ASSETS_DIR | Directory path where front-end packaged JavaScript is saved and loaded. _Required_. | | ASSETS_MAP_FILE | File name of map file, within ASSETS_DIR, containing map of general file names to unique build-specific file names. | | ASSIGNMENT_CONTACTS_SIDEBAR | Show a sidebar with a list of contacts to the texter. Allows texter to freely navigate between conversations, regardless of status. | +| ASSIGNMENT_LOAD_LIMIT | Limit of contacts to load at one time for an assignment. Used when Spoke is deployed on a service with time and bandwidth limitations, such as AWS Lambda. Type: integer | | AUTH0_DOMAIN | Domain name on Auth0 account, should end in `.auth0.com`, e.g. `example.auth0.com`. _Required_. | | AUTH0_CLIENT_ID | Client ID from Auth0 app. _Required_. | | AUTH0_CLIENT_SECRET | Client secret from Auth0 app. _Required_. | diff --git a/src/server/api/assignment.js b/src/server/api/assignment.js index debc700b6..730bbf61d 100644 --- a/src/server/api/assignment.js +++ b/src/server/api/assignment.js @@ -114,6 +114,14 @@ export function getContacts( query = query.where({ assignment_id: assignment.id }); + + let assignmentLoadLimit = getConfig("ASSIGNMENT_LOAD_LIMIT"); + if (assignmentLoadLimit) { + assignmentLoadLimit = parseInt(assignmentLoadLimit); + if (!isNaN(assignmentLoadLimit)) { + query.limit(assignmentLoadLimit); + } + } } if (contactsFilter) { From bfee0006d1eea360a836eda0c0533293b746b7d6 Mon Sep 17 00:00:00 2001 From: Kathy Nguyen Date: Mon, 4 Mar 2024 16:52:39 -0800 Subject: [PATCH 2/3] Update test --- dev-tools/.env.test | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-tools/.env.test b/dev-tools/.env.test index 341b8b3d4..bb9e37c82 100644 --- a/dev-tools/.env.test +++ b/dev-tools/.env.test @@ -26,3 +26,4 @@ PHONE_INVENTORY=1 ALLOW_SEND_ALL=false DST_REFERENCE_TIMEZONE='America/New_York' PASSPORT_STRATEGY=local +ASSIGNMENT_LOAD_LIMIT=1 From f9d00b79b67e4cd0e2c45ff6337e551c9780a5b0 Mon Sep 17 00:00:00 2001 From: Kathy Nguyen Date: Wed, 6 Mar 2024 12:43:05 -0800 Subject: [PATCH 3/3] Add jest tests --- __test__/server/api/assignment.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/__test__/server/api/assignment.test.js b/__test__/server/api/assignment.test.js index 67508111c..be1831457 100644 --- a/__test__/server/api/assignment.test.js +++ b/__test__/server/api/assignment.test.js @@ -219,4 +219,29 @@ describe("test getContacts timezone stuff only", () => { /^select \* from .campaign_contact. where .assignment_id. = 1.*/ ); }); // it + + it("returns the correct query -- assignment load limit not set", () => { + let query = getContacts( + assignment, + { validTimezone: null }, + organization, + campaign + ); + expect(query.toString()).not.toMatch( + /^select \* from .campaign_contact. where .assignment_id. = 1.* limit 1/ + ); + }); // it + + it("returns the correct query -- assignment load limit set", () => { + global["ASSIGNMENT_LOAD_LIMIT"] = 1; + let query = getContacts( + assignment, + { validTimezone: null }, + organization, + campaign + ); + expect(query.toString()).toMatch( + /^select \* from .campaign_contact. where .assignment_id. = 1.* limit 1/ + ); + }); // it }); // describe