Skip to content

Commit

Permalink
Fix query to avoid nullable fields in select for update in processOld…
Browse files Browse the repository at this point in the history
…Streams job (#1844)
  • Loading branch information
garrrikkotua committed Nov 15, 2023
1 parent 08bf721 commit b931f0a
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IntegrationStreamDataState,
IntegrationStreamState,
WebhookState,
WebhookType,
} from '@crowd/types'
import {
IInsertableWebhookStream,
Expand All @@ -31,26 +30,25 @@ export default class IntegrationStreamRepository extends RepositoryBase<Integrat
try {
const results = await this.db().any(
`
select iw.id,
SELECT iw.id,
iw."tenantId",
iw."integrationId",
iw.state,
iw.type,
iw.payload,
iw."createdAt" as "createdAt",
i.platform as "platform"
from "incomingWebhooks" iw
inner join integrations i on iw."integrationId" = i.id
left join integration.streams s on iw.id = s."webhookId"
where s.id is null
and iw.type <> $(discourseType)
and iw.state = $(pendingState)
and iw."createdAt" < now() - interval '1 hour'
limit ${limit}
for update skip locked;
iw."createdAt" AS "createdAt",
i.platform AS "platform"
FROM "incomingWebhooks" iw
INNER JOIN integrations i ON iw."integrationId" = i.id
WHERE NOT EXISTS (
SELECT 1 FROM integration.streams s WHERE iw.id = s."webhookId"
)
AND iw.state = $(pendingState)
AND iw."createdAt" < NOW() - INTERVAL '1 hour'
LIMIT ${limit}
FOR UPDATE SKIP LOCKED;
`,
{
discourseType: WebhookType.DISCOURSE,
pendingState: WebhookState.PENDING,
},
)
Expand Down

0 comments on commit b931f0a

Please # to comment.