Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/tweets/timeline/timeline.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ export class TimelineService {
// 2. Get tweet candidates from the Following timeline cache
const followingTweets = await this.getFollowingTimelineCandidates(userId, FOR_YOU_FEED_SIZE);
const followingTweetIds = new Set(followingTweets.map((t) => t.id)); // Keep track of which IDs came from this source
const followingAuthorIds = new Set(followingTweets.map((t) => t.authorId));

this.logger.debug(
`Got ${followingTweets.length} candidate tweets from Following timeline for user ${userId}`,
Expand Down Expand Up @@ -1275,14 +1276,22 @@ export class TimelineService {
}

const candidateTweetIds = candidates.map((c) => BigInt(c.id));
const candidateAuthorIds = new Set(candidates.map((c) => BigInt(c.authorId)));
const candidateAuthorIds = Array.from(new Set(candidates.map((c) => BigInt(c.authorId))));

const [validAuthorIds, validTweetIds] = await Promise.all([
this.tweetsRepository.filterNonMutedAuthors(userId, Array.from(candidateAuthorIds)),
const followingCandidateAuthorIds = candidateAuthorIds.filter((id) =>
followingAuthorIds.has(id.toString()),
);
const interestCandidateAuthorIds = candidateAuthorIds.filter(
(id) => !followingAuthorIds.has(id.toString()),
);

const [validFollowingAuthorIds, validInterestAuthorIds, validTweetIds] = await Promise.all([
this.tweetsRepository.filterValidAuthors(userId, followingCandidateAuthorIds),
this.tweetsRepository.filterNonMutedNonBlockedAuthors(userId, interestCandidateAuthorIds),
this.tweetsRepository.filterValidTweets(candidateTweetIds),
]);

validAuthorIds.push(userId);
const validAuthorIds = [userId, ...validFollowingAuthorIds, ...validInterestAuthorIds];

const validAuthorSet = new Set(validAuthorIds.map((id) => id.toString()));
const validTweetSet = new Set(validTweetIds.map((id) => id.toString()));
Expand Down
12 changes: 11 additions & 1 deletion src/tweets/tweets.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@
include: {
...tweetInclude(authUserId),
quotedTweet: {
include: tweetInclude(authUserId),

Check warning on line 983 in src/tweets/tweets.repository.ts

View workflow job for this annotation

GitHub Actions / Code Style & Quality

Unexpected console statement. Only these console methods are allowed: warn, error, info
},
replyToTweet: {
include: tweetInclude(authUserId),
Expand Down Expand Up @@ -1450,7 +1450,7 @@
return validFollows.map((f) => f.followedId);
}

async filterNonMutedAuthors(userId: bigint, authorIds: bigint[]): Promise<bigint[]> {
async filterNonMutedNonBlockedAuthors(userId: bigint, authorIds: bigint[]): Promise<bigint[]> {
const validAuthors = await this.prisma.user.findMany({
where: {
id: { in: authorIds },
Expand All @@ -1460,6 +1460,16 @@
userId: userId,
},
},
blockedBy: {
none: {
userId: userId,
},
},
blockedUsers: {
none: {
blockedId: userId,
},
},
},
select: { id: true },
});
Expand Down
Loading