refactor(flickr): add isAlreadyProcessed for greatest dedupe strategy

This commit is contained in:
Ali BARIN
2022-10-24 23:39:19 +02:00
parent b2caea9b9b
commit 524c3c22dc
2 changed files with 18 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ export default defineTrigger({
pollInterval: 15, pollInterval: 15,
key: 'newPhoto', key: 'newPhoto',
description: 'Triggers when you add a new photo.', description: 'Triggers when you add a new photo.',
dedupeStrategy: 'unique', dedupeStrategy: 'greatest',
substeps: [ substeps: [
{ {
key: 'chooseConnection', key: 'chooseConnection',

View File

@@ -87,16 +87,26 @@ const globalVariable = async (
beforeRequest: app.beforeRequest, beforeRequest: app.beforeRequest,
}); });
if (trigger && trigger.dedupeStrategy === 'unique') { if (trigger) {
const lastInternalIds = testRun ? [] : await flow?.lastInternalIds(); if (trigger.dedupeStrategy === 'unique') {
const lastInternalIds = testRun ? [] : await flow?.lastInternalIds();
const isAlreadyProcessed = (internalId: string) => { const isAlreadyProcessed = (internalId: string) => {
if (testRun) return false; if (testRun) return false;
return lastInternalIds?.includes(internalId); return lastInternalIds?.includes(internalId);
}; };
$.flow.isAlreadyProcessed = isAlreadyProcessed; $.flow.isAlreadyProcessed = isAlreadyProcessed;
} else if (trigger.dedupeStrategy === 'greatest') {
const isAlreadyProcessed = (internalId: string) => {
if (testRun) return false;
return Number(internalId) <= Number($.flow.lastInternalId);
};
$.flow.isAlreadyProcessed = isAlreadyProcessed;
}
} }
return $; return $;