1616 IssueComment ,
1717 IssueActivity ,
1818 UserNotificationPreference ,
19- ProjectMember
19+ ProjectMember ,
2020)
21+ from django .db .models import Subquery
2122
2223# Third Party imports
2324from celery import shared_task
@@ -95,7 +96,8 @@ def extract_mentions_as_subscribers(project_id, issue_id, mentions):
9596 ).exists ()
9697 and not Issue .objects .filter (
9798 project_id = project_id , pk = issue_id , created_by_id = mention_id
98- ).exists () and ProjectMember .objects .filter (
99+ ).exists ()
100+ and ProjectMember .objects .filter (
99101 project_id = project_id , member_id = mention_id , is_active = True
100102 ).exists ()
101103 ):
@@ -242,14 +244,19 @@ def notifications(
242244 2. From the latest set of mentions, extract the users which are not a subscribers & make them subscribers
243245 """
244246
247+ # get the list of active project members
248+ project_members = ProjectMember .objects .filter (
249+ project_id = project_id , is_active = True
250+ ).values_list ("member_id" , flat = True )
251+
245252 # Get new mentions from the newer instance
246253 new_mentions = get_new_mentions (
247254 requested_instance = requested_data , current_instance = current_instance
248255 )
249- new_mentions = list ( ProjectMember . objects . filter (
250- project_id = project_id , member_id__in = new_mentions , is_active = True
251- ). values_list ( "member_id" , flat = True ))
252- new_mentions = [ str ( member_id ) for member_id in new_mentions ]
256+
257+ new_mentions = [
258+ str ( mention ) for mention in new_mentions if mention in new_mentions
259+ ]
253260 removed_mention = get_removed_mentions (
254261 requested_instance = requested_data , current_instance = current_instance
255262 )
@@ -293,7 +300,11 @@ def notifications(
293300
294301 # ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #
295302 issue_subscribers = list (
296- IssueSubscriber .objects .filter (project_id = project_id , issue_id = issue_id , project__project_projectmember__is_active = True ,)
303+ IssueSubscriber .objects .filter (
304+ project_id = project_id ,
305+ issue_id = issue_id ,
306+ subscriber__in = Subquery (project_members ),
307+ )
297308 .exclude (
298309 subscriber_id__in = list (new_mentions + comment_mentions + [actor_id ])
299310 )
@@ -314,7 +325,9 @@ def notifications(
314325 project = Project .objects .get (pk = project_id )
315326
316327 issue_assignees = IssueAssignee .objects .filter (
317- issue_id = issue_id , project_id = project_id
328+ issue_id = issue_id ,
329+ project_id = project_id ,
330+ assignee__in = Subquery (project_members ),
318331 ).values_list ("assignee" , flat = True )
319332
320333 issue_subscribers = list (set (issue_subscribers ) - {uuid .UUID (actor_id )})
0 commit comments