unique member results

This commit is contained in:
Nils Büchner 2024-04-05 06:53:31 +02:00
parent 8b60597340
commit 58fa73addb

View file

@ -1,5 +1,6 @@
import redis import redis
import json import json
import traceback
from bugtracker.launchpad_singleton import get_launchpad from bugtracker.launchpad_singleton import get_launchpad
# Connect to Redis # Connect to Redis
@ -14,18 +15,11 @@ def fetch_individual_or_team_members(person_or_team, launchpad):
if person.is_team: if person.is_team:
ext = fetch_individual_or_team_members(person, launchpad) ext = fetch_individual_or_team_members(person, launchpad)
if ext and not person.is_team: if ext and not person.is_team:
members.append({ members.append(person.name)
'name': person_or_team.name,
})
else: else:
members.append({ members.append(person.name)
'name': person.name,
})
else: else:
# Append individual member details members.append(person_or_team.name)
members.append({
'name': person_or_team.name,
})
return members return members
def fetch_group_members(group_name): def fetch_group_members(group_name):
@ -38,15 +32,17 @@ def fetch_group_members(group_name):
launchpad = get_launchpad() launchpad = get_launchpad()
group = launchpad.people[group_name] group = launchpad.people[group_name]
group_members = [] group_members = set()
for person in group.members: for person in group.members:
ext = fetch_individual_or_team_members(person, launchpad) ext = fetch_individual_or_team_members(person, launchpad)
if ext: if ext:
group_members.extend(ext) for member in ext:
group_members.add(member)
# MXIDs should be generated for individuals only # MXIDs should be generated for individuals only
mxids = ['@' + member['name'] + ':ubuntu.com' for member in group_members] print(group_members)
result = {'group_members': group_members, 'group_name': group_name, 'mxids': mxids} mxids = ['@' + member + ':ubuntu.com' for member in group_members]
result = {'group_members': tuple(group_members), 'group_name': group_name, 'mxids': mxids}
# Cache the result with expiration time of 30 minutes (1800 seconds) # Cache the result with expiration time of 30 minutes (1800 seconds)
cache.setex(f"group_members_{group_name}", 1800, json.dumps(result)) cache.setex(f"group_members_{group_name}", 1800, json.dumps(result))
@ -54,7 +50,9 @@ def fetch_group_members(group_name):
return result return result
except KeyError as e: except KeyError as e:
print(f"Group with name {group_name} was not found. Error: {e}") print(f"Group with name {group_name} was not found. Error: {e}")
print(traceback.format_exc())
return False return False
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") print(f"An error occurred: {e}")
print(traceback.format_exc())
return False return False