Skip to content

Commit

Permalink
Remove unnecessary opensearch client initializations (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
epipav authored Nov 21, 2023
1 parent 8f9871e commit 89242fb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 39 deletions.
4 changes: 2 additions & 2 deletions backend/src/services/__tests__/tenantService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
})
})
Expand Down
19 changes: 6 additions & 13 deletions services/apps/search_sync_api/src/routes/activity.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
20 changes: 7 additions & 13 deletions services/apps/search_sync_api/src/routes/member.ts
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down
17 changes: 6 additions & 11 deletions services/apps/search_sync_api/src/routes/organization.ts
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down

0 comments on commit 89242fb

Please sign in to comment.