Skip to content

Commit f057e27

Browse files
authored
Fix lastProcessedAt for integrations receiving data via webhooks (#1757)
1 parent 4d0e629 commit f057e27

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

backend/src/database/repositories/integrationRepository.ts

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

511511
rows = await this._populateRelationsForRows(rows)
512512

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

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)