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) {
|
if (response.data.meta.result_count > 0) {
|
||||||
response.data.data.forEach((tweet: IJSONObject) => {
|
response.data.data.forEach((follower: IJSONObject) => {
|
||||||
if (
|
|
||||||
!options.lastInternalId ||
|
|
||||||
Number(tweet.id) > Number(options.lastInternalId)
|
|
||||||
) {
|
|
||||||
followers.data.push({
|
followers.data.push({
|
||||||
raw: tweet,
|
raw: follower,
|
||||||
meta: { internalId: tweet.id as string },
|
meta: { internalId: follower.id as string },
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} while (response.data.meta.next_token && options.lastInternalId);
|
} 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;
|
return followers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -61,21 +61,18 @@ const getUserTweets = async (
|
|||||||
|
|
||||||
if (response.data.meta.result_count > 0) {
|
if (response.data.meta.result_count > 0) {
|
||||||
response.data.data.forEach((tweet: IJSONObject) => {
|
response.data.data.forEach((tweet: IJSONObject) => {
|
||||||
if (
|
|
||||||
!options.lastInternalId ||
|
|
||||||
Number(tweet.id) > Number(options.lastInternalId)
|
|
||||||
) {
|
|
||||||
tweets.data.push({
|
tweets.data.push({
|
||||||
raw: tweet,
|
raw: tweet,
|
||||||
meta: { internalId: tweet.id as string },
|
meta: { internalId: tweet.id as string },
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} while (response.data.meta.next_token && options.lastInternalId);
|
} 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;
|
return tweets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -52,10 +52,6 @@ const searchTweets = async (
|
|||||||
|
|
||||||
if (response.data.meta.result_count > 0) {
|
if (response.data.meta.result_count > 0) {
|
||||||
response.data.data.forEach((tweet: IJSONObject) => {
|
response.data.data.forEach((tweet: IJSONObject) => {
|
||||||
if (
|
|
||||||
!options.lastInternalId ||
|
|
||||||
Number(tweet.id) > Number(options.lastInternalId)
|
|
||||||
) {
|
|
||||||
const dataItem = {
|
const dataItem = {
|
||||||
raw: tweet,
|
raw: tweet,
|
||||||
meta: {
|
meta: {
|
||||||
@@ -64,13 +60,14 @@ const searchTweets = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
tweets.data.push(dataItem);
|
tweets.data.push(dataItem);
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} while (response.data.meta.next_token && options.lastInternalId);
|
} 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;
|
return tweets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -59,14 +59,6 @@ class Processor {
|
|||||||
initialTriggerData.data = [initialTriggerData.data[0]];
|
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[] = [];
|
const executions: Execution[] = [];
|
||||||
|
|
||||||
for await (const data of initialTriggerData.data) {
|
for await (const data of initialTriggerData.data) {
|
||||||
|
Reference in New Issue
Block a user