A
A
Alexey Konovalov2018-07-18 21:03:16
MySQL
Alexey Konovalov, 2018-07-18 21:03:16

How to simplify or speed up the request?

Hello! Tell me, is there a more beautiful way to determine whether the user is a member of the community?
When selecting community lists, you need to constantly know if the current user is a member of each community ... As a result, the query turns out like this ...

SELECT g.`id`, g.`title`, g.`descr`, gm.`id` is_member 
FROM `groups` g
LEFT JOIN `groups_members` gm ON gm.`group_id` = gm.`id` AND gm.`user_id` = ".$this->user->getUserId()."
LIMIT 0, 20

The meaning of the code is as follows: we get a list of groups and some fields from them, and also using LEFT JOIN we try to get from the table responsible for storing data about community members a line where the community ID and member ID are equal to the current community and the current user (who applied to the script).
After, on the php side, I check if the value of is_member == NULL means the user is not a member of the community.
Is this the right approach? What if you need a lot of such checks and with different tables?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2018-07-18
@kawabanga

Here you will have a bot, with 30-40K intros, exits. And everything will hang on one user.
Why do you need to make a selection with the name and description of the group in advance? I would make two requests.
1) would choose groups where the user participates.
2) Uploaded the description of the groups.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question