From 89242fbd30ffa75677c1c50fff182cc7aa19a598 Mon Sep 17 00:00:00 2001 From: anilb Date: Tue, 21 Nov 2023 11:23:38 +0100 Subject: [PATCH] Remove unnecessary opensearch client initializations (#1863) --- .../services/__tests__/tenantService.test.ts | 4 ++-- .../search_sync_api/src/routes/activity.ts | 19 ++++++------------ .../apps/search_sync_api/src/routes/member.ts | 20 +++++++------------ .../src/routes/organization.ts | 17 ++++++---------- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/backend/src/services/__tests__/tenantService.test.ts b/backend/src/services/__tests__/tenantService.test.ts index 8ac680bbfc..c2cc9666d3 100644 --- a/backend/src/services/__tests__/tenantService.test.ts +++ b/backend/src/services/__tests__/tenantService.test.ts @@ -222,8 +222,8 @@ describe('TenantService tests', () => { 'Engage with relevant content', 'Reach out to influential contacts', 'Reach out to poorly engaged contacts', - 'Setup your team', - 'Setup your workpace integrations', + 'Set up your team', + 'Set up your workspace integrations', ]) }) }) diff --git a/services/apps/search_sync_api/src/routes/activity.ts b/services/apps/search_sync_api/src/routes/activity.ts index 3e7e563072..67821fe02d 100644 --- a/services/apps/search_sync_api/src/routes/activity.ts +++ b/services/apps/search_sync_api/src/routes/activity.ts @@ -1,17 +1,14 @@ import express from 'express' -import { ActivitySyncService, OpenSearchService } from '@crowd/opensearch' +import { ActivitySyncService } from '@crowd/opensearch' import { ApiRequest } from '../middleware/index' import { asyncWrap } from 'middleware/error' -import { OPENSEARCH_CONFIG } from 'conf' const router = express.Router() -const opensearchConfig = OPENSEARCH_CONFIG() router.post( '/sync/activities', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) - const activitySyncService = new ActivitySyncService(req.dbStore, openSearchService, req.log) + const activitySyncService = new ActivitySyncService(req.dbStore, req.opensearch, req.log) const { activityIds } = req.body try { await activitySyncService.syncActivities(activityIds) @@ -25,8 +22,7 @@ router.post( router.post( '/sync/tenant/activities', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) - const activitySyncService = new ActivitySyncService(req.dbStore, openSearchService, req.log) + const activitySyncService = new ActivitySyncService(req.dbStore, req.opensearch, req.log) const { tenantId } = req.body try { @@ -41,8 +37,7 @@ router.post( router.post( '/sync/organization/activities', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) - const activitySyncService = new ActivitySyncService(req.dbStore, openSearchService, req.log) + const activitySyncService = new ActivitySyncService(req.dbStore, req.opensearch, req.log) const { organizationId } = req.body try { @@ -57,8 +52,7 @@ router.post( router.post( '/cleanup/tenant/activities', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) - const activitySyncService = new ActivitySyncService(req.dbStore, openSearchService, req.log) + const activitySyncService = new ActivitySyncService(req.dbStore, req.opensearch, req.log) const { tenantId } = req.body try { @@ -73,8 +67,7 @@ router.post( router.post( '/cleanup/activity', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) - const activitySyncService = new ActivitySyncService(req.dbStore, openSearchService, req.log) + const activitySyncService = new ActivitySyncService(req.dbStore, req.opensearch, req.log) const { activityId } = req.body try { diff --git a/services/apps/search_sync_api/src/routes/member.ts b/services/apps/search_sync_api/src/routes/member.ts index b4c2108b10..51cb15d191 100644 --- a/services/apps/search_sync_api/src/routes/member.ts +++ b/services/apps/search_sync_api/src/routes/member.ts @@ -1,21 +1,19 @@ import express from 'express' -import { MemberSyncService, OpenSearchService } from '@crowd/opensearch' +import { MemberSyncService } from '@crowd/opensearch' import { ApiRequest } from 'middleware' import { asyncWrap } from 'middleware/error' -import { OPENSEARCH_CONFIG, SERVICE_CONFIG } from 'conf' +import { SERVICE_CONFIG } from 'conf' const router = express.Router() -const opensearchConfig = OPENSEARCH_CONFIG() const serviceConfig = SERVICE_CONFIG() router.post( '/sync/members', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) const memberSyncService = new MemberSyncService( req.redisClient, req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -33,11 +31,10 @@ router.post( router.post( '/sync/tenant/members', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) const memberSyncService = new MemberSyncService( req.redisClient, req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -55,11 +52,10 @@ router.post( router.post( '/sync/organization/members', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) const memberSyncService = new MemberSyncService( req.redisClient, req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -77,11 +73,10 @@ router.post( router.post( '/cleanup/tenant/members', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) const memberSyncService = new MemberSyncService( req.redisClient, req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -99,11 +94,10 @@ router.post( router.post( '/cleanup/member', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, opensearchConfig) const memberSyncService = new MemberSyncService( req.redisClient, req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) diff --git a/services/apps/search_sync_api/src/routes/organization.ts b/services/apps/search_sync_api/src/routes/organization.ts index 9c84814a59..add478f036 100644 --- a/services/apps/search_sync_api/src/routes/organization.ts +++ b/services/apps/search_sync_api/src/routes/organization.ts @@ -1,20 +1,18 @@ import express from 'express' -import { OpenSearchService, OrganizationSyncService } from '@crowd/opensearch' +import { OrganizationSyncService } from '@crowd/opensearch' import { ApiRequest } from 'middleware' import { asyncWrap } from 'middleware/error' -import { OPENSEARCH_CONFIG, SERVICE_CONFIG } from 'conf' +import { SERVICE_CONFIG } from 'conf' const router = express.Router() -const openSearchConfig = OPENSEARCH_CONFIG() const serviceConfig = SERVICE_CONFIG() router.post( '/sync/organizations', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, openSearchConfig) const organizationSyncService = new OrganizationSyncService( req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -31,10 +29,9 @@ router.post( router.post( '/sync/tenant/organizations', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, openSearchConfig) const organizationSyncService = new OrganizationSyncService( req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -52,10 +49,9 @@ router.post( router.post( '/cleanup/tenant/organizations', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, openSearchConfig) const organizationSyncService = new OrganizationSyncService( req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, ) @@ -73,10 +69,9 @@ router.post( router.post( '/cleanup/organization', asyncWrap(async (req: ApiRequest, res) => { - const openSearchService = new OpenSearchService(req.log, openSearchConfig) const organizationSyncService = new OrganizationSyncService( req.dbStore, - openSearchService, + req.opensearch, req.log, serviceConfig, )