[mastodon-client] Better home timeline query

This commit is contained in:
Laura Hausmann 2023-09-28 02:28:26 +02:00
parent 35e35c0998
commit d8659b5a94
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605

View File

@ -18,9 +18,9 @@ export class TimelineHelpers {
public static async getHomeTimeline(user: ILocalUser, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20): Promise<Note[]> { public static async getHomeTimeline(user: ILocalUser, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20): Promise<Note[]> {
if (limit > 40) limit = 40; if (limit > 40) limit = 40;
const followingIds = await Followings.findBy({ const followingQuery = Followings.createQueryBuilder("following")
followerId: user.id .select("following.followeeId")
}).then(res => res.map(p => p.followeeId)); .where("following.followerId = :followerId", {followerId: user.id});
const query = PaginationHelpers.makePaginationQuery( const query = PaginationHelpers.makePaginationQuery(
Notes.createQueryBuilder("note"), Notes.createQueryBuilder("note"),
@ -30,8 +30,7 @@ export class TimelineHelpers {
) )
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.where("note.userId = :meId", {meId: user.id}); qb.where(`note.userId IN (${followingQuery.getQuery()} UNION ALL VALUES (:meId))`, {meId: user.id});
qb.orWhere(`note.userId IN (:...followingIds)`, {followingIds: followingIds});
}), }),
) )
.leftJoinAndSelect("note.renote", "renote"); .leftJoinAndSelect("note.renote", "renote");