Skip to content

Commit

Permalink
Merge pull request activepieces#5341 from activepieces/fix/event-rout…
Browse files Browse the repository at this point in the history
…ing-1

fix: db index on app event routing
  • Loading branch information
abuaboud authored Aug 13, 2024
2 parents 90beb6a + 5c67545 commit fdd00da
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const AppEventRoutingEntity = new EntitySchema<AppEventRouting>({
unique: false,
},
{
name: 'idx_app_event_project_id_appName_identifier_value_event',
columns: ['appName', 'projectId', 'identifierValue', 'event'],
name: 'idx_app_event_flow_id_project_id_appName_identifier_value_event',
columns: ['appName', 'projectId', 'flowId', 'identifierValue', 'event'],
unique: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ import {
AppEventRoutingEntity,
} from './app-event-routing.entity'

const appEventRoutingRepo = repoFactory(
AppEventRoutingEntity,
)
const appEventRoutingRepo = repoFactory(AppEventRoutingEntity)

export const appEventRoutingService = {
async listListeners({
appName,
event,
identifierValue,
}: {
appName: string
event: string
identifierValue: string
}): Promise<AppEventRouting[]> {
}: ListParams): Promise<AppEventRouting[]> {
return appEventRoutingRepo().findBy({ appName, event, identifierValue })
},
async createListeners({
Expand All @@ -28,16 +22,14 @@ export const appEventRoutingService = {
identifierValue,
flowId,
projectId,
}: {
appName: string
events: string[]
identifierValue: string
flowId: FlowId
projectId: ProjectId
}): Promise<void> {
logger.info(
`Creating listeners for ${appName}, events=${events}, identifierValue=${identifierValue}`,
)
}: CreateParams): Promise<void> {
logger.info({
appName,
events,
identifierValue,
flowId,
projectId,
}, '[AppEventRoutingService#createListeners] create')
const upsertCommands: Promise<unknown>[] = []
events.forEach((event) => {
const upsert = appEventRoutingRepo().upsert(
Expand All @@ -49,7 +41,7 @@ export const appEventRoutingService = {
flowId,
projectId,
},
['appName', 'event', 'identifierValue', 'projectId'],
['appName', 'event', 'identifierValue', 'projectId', 'flowId'],
)
upsertCommands.push(upsert)
})
Expand All @@ -58,13 +50,28 @@ export const appEventRoutingService = {
async deleteListeners({
projectId,
flowId,
}: {
projectId: ProjectId
flowId: FlowId
}): Promise<void> {
}: DeleteParams): Promise<void> {
await appEventRoutingRepo().delete({
projectId,
flowId,
})
},
}

type ListParams = {
appName: string
event: string
identifierValue: string
}
type DeleteParams = {
projectId: ProjectId
flowId: FlowId
}

type CreateParams = {
appName: string
events: string[]
identifierValue: string
flowId: FlowId
projectId: ProjectId
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm'

export class ChangeEventRoutingConstraint1723549873495 implements MigrationInterface {
name = 'ChangeEventRoutingConstraint1723549873495'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "idx_app_event_project_id_appName_identifier_value_event"
`)
await queryRunner.query(`
CREATE UNIQUE INDEX "idx_app_event_flow_id_project_id_appName_identifier_value_event" ON "app_event_routing" (
"appName",
"projectId",
"flowId",
"identifierValue",
"event"
)
`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "idx_app_event_flow_id_project_id_appName_identifier_value_event"
`)
await queryRunner.query(`
CREATE UNIQUE INDEX "idx_app_event_project_id_appName_identifier_value_event" ON "app_event_routing" (
"appName",
"projectId",
"identifierValue",
"event"
)
`)
}

}
2 changes: 2 additions & 0 deletions packages/server/api/src/app/database/postgres-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { AddTriggerTestStrategy1707087022764 } from './migration/common/17070870
import { MigrateWebhook1709581196563 } from './migration/common/1709581196563-migrate-webhook'
import { RemoveShowActivityLog1716105958530 } from './migration/common/1716105958530-RemoveShowActivityLog'
import { AddDurationForRuns1716725027424 } from './migration/common/1716725027424-AddDurationForRuns'
import { ChangeEventRoutingConstraint1723549873495 } from './migration/common/1723549873495-ChangeEventRoutingConstraint'
import { AddAuthToPiecesMetadata1688922241747 } from './migration/postgres//1688922241747-AddAuthToPiecesMetadata'
import { FlowAndFileProjectId1674788714498 } from './migration/postgres/1674788714498-FlowAndFileProjectId'
import { initializeSchema1676238396411 } from './migration/postgres/1676238396411-initialize-schema'
Expand Down Expand Up @@ -230,6 +231,7 @@ const getMigrations = (): (new () => MigrationInterface)[] => {
AddUserInvitation1717960689650,
AddPremiumPiecesColumnPostgres1717370717678,
AddWorkerMachine1720101280025,
ChangeEventRoutingConstraint1723549873495,
]

const edition = system.getEdition()
Expand Down
2 changes: 2 additions & 0 deletions packages/server/api/src/app/database/sqlite-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AddTriggerTestStrategy1707087022764 } from './migration/common/17070870
import { MigrateWebhook1709581196563 } from './migration/common/1709581196563-migrate-webhook'
import { RemoveShowActivityLog1716105958530 } from './migration/common/1716105958530-RemoveShowActivityLog'
import { AddDurationForRuns1716725027424 } from './migration/common/1716725027424-AddDurationForRuns'
import { ChangeEventRoutingConstraint1723549873495 } from './migration/common/1723549873495-ChangeEventRoutingConstraint'
import { InitialSql3Migration1690195839899 } from './migration/sqlite/1690195839899-InitialSql3Migration'
import { AddAppConnectionTypeToTopLevel1691706020626 } from './migration/sqlite/1691706020626-add-app-connection-type-to-top-level'
import { AddTagsToRunSqlite1692056190942 } from './migration/sqlite/1692056190942-AddTagsToRunSqlite'
Expand Down Expand Up @@ -118,6 +119,7 @@ const getMigrations = (): (new () => MigrationInterface)[] => {
AddUserInvitationSqlite1717943564437,
AddPremiumPiecesColumnSqlite1717443603235,
AddWorkerMachineSqlite1720100928449,
ChangeEventRoutingConstraint1723549873495,
]
const edition = system.getEdition()
if (edition !== ApEdition.COMMUNITY) {
Expand Down

0 comments on commit fdd00da

Please sign in to comment.