[backend] Use more efficient home timeline heuristics query

This commit is contained in:
Laura Hausmann 2023-11-24 03:59:22 +01:00
parent b9b669570b
commit 7aa3bdb641
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -23,7 +23,12 @@ export async function generateFollowingQuery(
return Notes.createQueryBuilder('note') return Notes.createQueryBuilder('note')
.where(`note.createdAt > :prev`, { prev }) .where(`note.createdAt > :prev`, { prev })
.andWhere(`note.createdAt < :curr`, { curr }) .andWhere(`note.createdAt < :curr`, { curr })
.andWhere(`note.userId = ANY(array(${followingQuery.getQuery()} UNION ALL VALUES (:meId)))`, { meId: me.id }) .andWhere(
new Brackets((qb) => {
qb.where(`note.userId IN (${followingQuery.getQuery()})`);
qb.orWhere(`note.userId = :meId`, { meId: me.id });
})
)
.getCount() .getCount()
.then(res => { .then(res => {
logger.info(`Calculating heuristics for user ${me.id} took ${new Date().getTime() - curr.getTime()}ms`); logger.info(`Calculating heuristics for user ${me.id} took ${new Date().getTime() - curr.getTime()}ms`);