Skip to content

Commit

Permalink
fix: duplicated api calls (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgrasset authored Oct 27, 2023
1 parent 0cd2d0c commit df5968f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export const DEBUG = (process.env.TOUITOMAMOUT_DEBUG || "false") === "true";
export const DAEMON = (process.env.DAEMON || "false") === "true";
export const DAEMON_PERIOD_MIN = parseInt(process.env.DAEMON_PERIOD_MIN ?? "7"); // Default 7 min
export const VOID = "∅";
export const API_RATE_LIMIT = parseInt(process.env.API_RATE_LIMIT ?? "60");
export const API_RATE_LIMIT = parseInt(process.env.API_RATE_LIMIT ?? "10");
10 changes: 0 additions & 10 deletions src/helpers/tweet/__tests__/get-tweet-id-from-permalink.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/helpers/tweet/get-tweet-id-from-permalink.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/helpers/tweet/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from "./format-tweet-text.js";
export * from "./get-tweet-id-from-permalink.js";
export * from "./is-tweet-cached.js";
export * from "./keep-recent-tweets.js";
export * from "./keep-self-quotes.js";
Expand Down
25 changes: 1 addition & 24 deletions src/services/tweets-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { API_RATE_LIMIT, TWITTER_HANDLE } from "../constants.js";
import { getCache } from "../helpers/cache/index.js";
import { oraPrefixer } from "../helpers/logs/ora-prefixer.js";
import { getEligibleTweet } from "../helpers/tweet/get-eligible-tweet.js";
import {
formatTweetText,
getTweetIdFromPermalink,
isTweetCached,
} from "../helpers/tweet/index.js";
import { formatTweetText, isTweetCached } from "../helpers/tweet/index.js";

const pullContentStats = (tweets: Tweet[], title: string) => {
const stats = {
Expand Down Expand Up @@ -54,29 +50,10 @@ export const tweetsGetterService = async (

const t: Tweet = {
...tweet,
id: getTweetIdFromPermalink(tweet.id || ""),
timestamp: (tweet.timestamp ?? 0) * 1000,
text: formatTweetText(tweet),
};

// Inject quoted tweet
if (tweet.quotedStatusId) {
const quotedStatus = await twitterClient.getTweet(tweet.quotedStatusId);
if (quotedStatus) {
t.quotedStatus = quotedStatus;
}
}

// Inject in reply tweet
if (tweet.inReplyToStatusId) {
const inReplyStatus = await twitterClient.getTweet(
tweet.inReplyToStatusId,
);
if (inReplyStatus) {
t.inReplyToStatus = inReplyStatus;
}
}

const eligibleTweet = await getEligibleTweet(t);
if (eligibleTweet) {
tweets.unshift(eligibleTweet);
Expand Down

0 comments on commit df5968f

Please sign in to comment.