import { Op } from 'sequelize' import { SilencedPost } from '../../db.js' import { redisCache } from '../redis.js' async function getMutedPosts(userId: string, superMute = false): Promise> { let res: string[] = [] const cacheResult = await redisCache.get((superMute ? 'superMutedPosts' : 'mutedPosts:') + userId) if (cacheResult) { res = JSON.parse(cacheResult) } else { const mutedPostsQuery = await SilencedPost.findAll({ where: { userId: userId, superMuted: superMute ? true : { [Op.in]: [true, false, null, undefined] // yeah ok this is a bit dirty haha but its only one code path } }, attributes: ['postId'] }) res = mutedPostsQuery.map((elem: any) => elem.postId) await redisCache.set((superMute ? 'superMutedPosts:' : 'mutedPosts:') + userId, JSON.stringify(res), 'EX', 600) } return res } export { getMutedPosts }