refactor: Remove early exit strategy for twitter triggers
This commit is contained in:
@@ -49,22 +49,19 @@ const getUserFollowers = async (
|
||||
}
|
||||
|
||||
if (response.data.meta.result_count > 0) {
|
||||
response.data.data.forEach((tweet: IJSONObject) => {
|
||||
if (
|
||||
!options.lastInternalId ||
|
||||
Number(tweet.id) > Number(options.lastInternalId)
|
||||
) {
|
||||
followers.data.push({
|
||||
raw: tweet,
|
||||
meta: { internalId: tweet.id as string },
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
response.data.data.forEach((follower: IJSONObject) => {
|
||||
followers.data.push({
|
||||
raw: follower,
|
||||
meta: { internalId: follower.id as string },
|
||||
});
|
||||
});
|
||||
}
|
||||
} while (response.data.meta.next_token && options.lastInternalId);
|
||||
|
||||
followers.data.sort((follower, nextFollower) => {
|
||||
return (follower.raw.id as number) - (nextFollower.raw.id as number);
|
||||
});
|
||||
|
||||
return followers;
|
||||
};
|
||||
|
||||
|
@@ -61,21 +61,18 @@ const getUserTweets = async (
|
||||
|
||||
if (response.data.meta.result_count > 0) {
|
||||
response.data.data.forEach((tweet: IJSONObject) => {
|
||||
if (
|
||||
!options.lastInternalId ||
|
||||
Number(tweet.id) > Number(options.lastInternalId)
|
||||
) {
|
||||
tweets.data.push({
|
||||
raw: tweet,
|
||||
meta: { internalId: tweet.id as string },
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
tweets.data.push({
|
||||
raw: tweet,
|
||||
meta: { internalId: tweet.id as string },
|
||||
});
|
||||
});
|
||||
}
|
||||
} while (response.data.meta.next_token && options.lastInternalId);
|
||||
|
||||
tweets.data.sort((tweet, nextTweet) => {
|
||||
return (tweet.raw.id as number) - (nextTweet.raw.id as number);
|
||||
});
|
||||
|
||||
return tweets;
|
||||
};
|
||||
|
||||
|
@@ -52,25 +52,22 @@ const searchTweets = async (
|
||||
|
||||
if (response.data.meta.result_count > 0) {
|
||||
response.data.data.forEach((tweet: IJSONObject) => {
|
||||
if (
|
||||
!options.lastInternalId ||
|
||||
Number(tweet.id) > Number(options.lastInternalId)
|
||||
) {
|
||||
const dataItem = {
|
||||
raw: tweet,
|
||||
meta: {
|
||||
internalId: tweet.id as string,
|
||||
},
|
||||
};
|
||||
const dataItem = {
|
||||
raw: tweet,
|
||||
meta: {
|
||||
internalId: tweet.id as string,
|
||||
},
|
||||
};
|
||||
|
||||
tweets.data.push(dataItem);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
tweets.data.push(dataItem);
|
||||
});
|
||||
}
|
||||
} while (response.data.meta.next_token && options.lastInternalId);
|
||||
|
||||
tweets.data.sort((tweet, nextTweet) => {
|
||||
return (tweet.raw.id as number) - (nextTweet.raw.id as number);
|
||||
});
|
||||
|
||||
return tweets;
|
||||
};
|
||||
|
||||
|
@@ -59,14 +59,6 @@ class Processor {
|
||||
initialTriggerData.data = [initialTriggerData.data[0]];
|
||||
}
|
||||
|
||||
if (initialTriggerData.data.length > 1) {
|
||||
initialTriggerData.data = initialTriggerData.data.sort(
|
||||
(item, nextItem) => {
|
||||
return (item.raw.id as number) - (nextItem.raw.id as number);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const executions: Execution[] = [];
|
||||
|
||||
for await (const data of initialTriggerData.data) {
|
||||
|
Reference in New Issue
Block a user