unique member results
This commit is contained in:
parent
8b60597340
commit
58fa73addb
1 changed files with 12 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
import redis
|
||||
import json
|
||||
import traceback
|
||||
from bugtracker.launchpad_singleton import get_launchpad
|
||||
|
||||
# Connect to Redis
|
||||
|
@ -14,18 +15,11 @@ def fetch_individual_or_team_members(person_or_team, launchpad):
|
|||
if person.is_team:
|
||||
ext = fetch_individual_or_team_members(person, launchpad)
|
||||
if ext and not person.is_team:
|
||||
members.append({
|
||||
'name': person_or_team.name,
|
||||
})
|
||||
members.append(person.name)
|
||||
else:
|
||||
members.append({
|
||||
'name': person.name,
|
||||
})
|
||||
members.append(person.name)
|
||||
else:
|
||||
# Append individual member details
|
||||
members.append({
|
||||
'name': person_or_team.name,
|
||||
})
|
||||
members.append(person_or_team.name)
|
||||
return members
|
||||
|
||||
def fetch_group_members(group_name):
|
||||
|
@ -38,15 +32,17 @@ def fetch_group_members(group_name):
|
|||
launchpad = get_launchpad()
|
||||
group = launchpad.people[group_name]
|
||||
|
||||
group_members = []
|
||||
group_members = set()
|
||||
for person in group.members:
|
||||
ext = fetch_individual_or_team_members(person, launchpad)
|
||||
if ext:
|
||||
group_members.extend(ext)
|
||||
for member in ext:
|
||||
group_members.add(member)
|
||||
|
||||
# MXIDs should be generated for individuals only
|
||||
mxids = ['@' + member['name'] + ':ubuntu.com' for member in group_members]
|
||||
result = {'group_members': group_members, 'group_name': group_name, 'mxids': mxids}
|
||||
print(group_members)
|
||||
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.setex(f"group_members_{group_name}", 1800, json.dumps(result))
|
||||
|
@ -54,7 +50,9 @@ def fetch_group_members(group_name):
|
|||
return result
|
||||
except KeyError as e:
|
||||
print(f"Group with name {group_name} was not found. Error: {e}")
|
||||
print(traceback.format_exc())
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
print(traceback.format_exc())
|
||||
return False
|
||||
|
|
Loading…
Reference in a new issue