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,
key: 'newPhoto',
description: 'Triggers when you add a new photo.',
dedupeStrategy: 'unique',
dedupeStrategy: 'greatest',
substeps: [
{
key: 'chooseConnection',

View File

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