Skip to content

Commit e772bfc

Browse files
committed
Fix lastsync for integrations receiving data via webhooks
1 parent e8ac18a commit e772bfc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

backend/src/database/repositories/integrationRepository.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,32 @@ class IntegrationRepository {
510510

511511
rows = await this._populateRelationsForRows(rows)
512512

513+
const seq = SequelizeRepository.getSequelize(options)
514+
515+
// Some integrations (i.e GitHub, Discord, Discourse, Groupsio) receive new data via webhook post-onboarding.
516+
// We track their last processedAt separately, and not using updatedAt.
517+
const results = await seq.query(
518+
`select "integrationId", max("processedAt") as "processedAt" from "incomingWebhooks"
519+
where "integrationId" in (:integrationIds) and state = 'PROCESSED'
520+
group by "integrationId"`,
521+
{
522+
replacements: {
523+
integrationIds: rows.map((row) => row.id),
524+
},
525+
type: QueryTypes.SELECT,
526+
transaction: SequelizeRepository.getTransaction(options),
527+
},
528+
) as any[]
529+
530+
const processedAtMap = results.reduce((map, item) => {
531+
map[item.integrationId] = item.processedAt
532+
return map
533+
}, {})
534+
535+
rows.forEach((row) => {
536+
row.lastProcessedAt = processedAtMap[row.id] || row.updatedAt
537+
})
538+
513539
return { rows, count, limit: parsed.limit, offset: parsed.offset }
514540
}
515541

frontend/src/modules/integration/components/integration-list-item.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ const isNeedsToBeReconnected = computed(
177177
);
178178
179179
const lastSynced = computed(() => ({
180-
absolute: moment(props.integration.updatedAt).format('MMM DD, YYYY HH:mm'),
181-
relative: `last synced ${moment(props.integration.updatedAt).fromNow()}`,
180+
absolute: moment(props.integration.lastProcessedAt).format('MMM DD, YYYY HH:mm'),
181+
relative: `last synced ${moment(props.integration.lastProcessedAt).fromNow()}`,
182182
}));
183183
184184
const loadingDisconnect = ref(false);

0 commit comments

Comments
 (0)