friends query improvement
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 33s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 33s
This commit is contained in:
@@ -60,10 +60,15 @@ router.get('/', authMiddleware, asyncHandler(async (req, res) => {
|
|||||||
FROM challenges c
|
FROM challenges c
|
||||||
INNER JOIN challenge_participants cp ON cp.challenge_id = c.id
|
INNER JOIN challenge_participants cp ON cp.challenge_id = c.id
|
||||||
WHERE cp.user_id = ? AND c.created_by != ? AND cp.status = 'accepted'
|
WHERE cp.user_id = ? AND c.created_by != ? AND cp.status = 'accepted'
|
||||||
|
UNION
|
||||||
|
SELECT DISTINCT cp.user_id
|
||||||
|
FROM challenge_participants cp
|
||||||
|
INNER JOIN challenges c ON cp.challenge_id = c.id
|
||||||
|
WHERE c.created_by = ? AND cp.user_id != ? AND cp.status = 'accepted'
|
||||||
)
|
)
|
||||||
AND u.id NOT IN (${friends.map(() => '?').join(',') || 'NULL'})
|
AND u.id NOT IN (${friends.map(() => '?').join(',') || 'NULL'})
|
||||||
ORDER BY u.username`,
|
ORDER BY u.username`,
|
||||||
[req.user.userId, req.user.userId, req.user.userId, req.user.userId, ...friends.map(f => f.id)]
|
[req.user.userId, req.user.userId, req.user.userId, req.user.userId, req.user.userId, req.user.userId, ...friends.map(f => f.id)]
|
||||||
);
|
);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
Reference in New Issue
Block a user