public inbox for [email protected]  
help / color / mirror / Atom feed
From: Brice AndrĂ© <[email protected]>
To: [email protected]
Subject: Most efficient way to select events from users having common subscriptions
Date: Mon, 22 Aug 2022 08:52:41 +0200
Message-ID: <CAOBG12mB0Vhx11xq73K2Yxjxg35Ayw9vSzsz-Hv06xNJGgXbSA@mail.gmail.com> (raw)

Hello,

I have a project on which users may be registered to different challenges.
And I would want to implement a "news" panel, where users are notified of
events performed by other users, which have at least one challenge in
common.

My DB schema has tables like follows :

   - table "user"
      - user_id
      - etc.
   - table "challenge"
      - challenge_id
      - etc.
   - table "user_challenge_association"
      - user_id
      - challenge_id
      - team_id
   - table "activity"
      - user_id

I would thus want to perform a request returning all activities of all
users which have at least one entry in "user_challenge_association" where
"challenge_id" is the same as another entry in "user_challenge_association"
associated to the user for which I am doing the request.

Imagine "user" contains (user_1, user_2, user_3), imaging "challenge"
contains (challenge_1, challenge_2), imagine that user_1 is only registered
to challenge_1 user_2 is only registered to challenge_2, and user_3 is
registered to both challenges, I would want :

   - that request for user_1 only returns activities of user_3
   - that request for user_2 only returns activities of user_3
   - that request for user_3 returns activities of user_1 and user_2

What would be the best way to perform such a query ?

Additional question : How could I integrate in the result a column
indicating if, in all existing challenges, the resulting activity is linked
to a user that was at least once in the same team as the user for which we
perform the request ? (team information is in "user_challenge_association"
table

Many thanks for your advices,
Brice


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Most efficient way to select events from users having common subscriptions
  In-Reply-To: <CAOBG12mB0Vhx11xq73K2Yxjxg35Ayw9vSzsz-Hv06xNJGgXbSA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox