Skip to content

Commit

Permalink
Refactor user recommendation query to exclude
Browse files Browse the repository at this point in the history
following users
  • Loading branch information
noxethiems committed Dec 7, 2023
1 parent b98ca1e commit 587e776
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions identity_socializer/db/dao/user_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,14 @@ async def get_recommended_users(
return []

following = await RelationshipDAO(self.session).get_following_by_id(user_id)
following_ids = [user.id for user in following]
following_id = [user.id for user in following]

print(following_ids)
excluded_ids = [user_id]
excluded_ids.extend(following_id)

query = select(UserModel)
query = query.where(UserModel.id != user_id)
query = query.where(not_(UserModel.id.in_(following_ids)))
query = query.where(not_(UserModel.id.in_(excluded_ids)))
query = query.where(UserModel.ubication == user.ubication)
query = query.where(UserModel.interests.overlap(user.interests))
query = query.order_by(func.random())
Expand All @@ -230,10 +231,8 @@ async def get_recommended_users(
rows = await self.session.execute(query)
recommendations = list(rows.scalars().fetchall())

print(recommendations)

excluded_ids = [user_id] + following_ids
excluded_ids = [user.id for user in recommendations]
recommendations_ids = [user.id for user in recommendations]
excluded_ids.extend(recommendations_ids)

random_users = await self._get_random_users(
user_id,
Expand Down

0 comments on commit 587e776

Please sign in to comment.