Skip to content

Commit

Permalink
feat : 추천유저 응답 시간 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTH916 authored Dec 7, 2023
1 parent 81cc509 commit 2b17f8e
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions be/src/user/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,36 @@ export class UserRepository extends Repository<User> {
}

async getRecommendUserListInfo(idList: number[], id: number) {
const curUser = await this.findOne({
select: ["id", "region"],
where: { id: id },
});

const myRestaurants = await this.createQueryBuilder("user")
.leftJoinAndSelect("user.restaurant", "userRestaurant")
.where("user.id = :id", { id })
.select("userRestaurant.restaurantId")
.getRawMany();

const myFavRestaurants = myRestaurants.map(
(r) => r.userRestaurant_restaurant_id
);

const userInfo = await this.createQueryBuilder("user")
.select(["user.nickName", "user.region"])
.leftJoin("user.restaurant", "userRestaurant")
.select([
"user.nickName",
"user.region",
'SUM(CASE WHEN userRestaurant.restaurantId IN (:...myFavRestaurants) THEN 1 ELSE 0 END) AS "commonRestaurant"',
])
.setParameter("myFavRestaurants", myFavRestaurants)
.where("user.id NOT IN (:...idList)", { idList })
.orderBy("RANDOM()")
.limit(2)
.getMany();
.andWhere("user.region = :yourRegion", { yourRegion: curUser.region })
.groupBy("user.id")
.orderBy("\"commonRestaurant\"", "DESC")
.limit(10)
.getRawMany();

return userInfo;
}

Expand Down

0 comments on commit 2b17f8e

Please sign in to comment.