remove recursion
This commit is contained in:
parent
58fa73addb
commit
616564c21b
2 changed files with 7 additions and 22 deletions
|
@ -6,23 +6,8 @@ from bugtracker.launchpad_singleton import get_launchpad
|
||||||
# Connect to Redis
|
# Connect to Redis
|
||||||
cache = redis.Redis(host='localhost', port=6379, db=0)
|
cache = redis.Redis(host='localhost', port=6379, db=0)
|
||||||
|
|
||||||
def fetch_individual_or_team_members(person_or_team, launchpad):
|
|
||||||
members = []
|
|
||||||
if person_or_team.is_team:
|
|
||||||
# Recursively fetch members for a team
|
|
||||||
group = launchpad.people[person_or_team.name]
|
|
||||||
for person in group.members:
|
|
||||||
if person.is_team:
|
|
||||||
ext = fetch_individual_or_team_members(person, launchpad)
|
|
||||||
if ext and not person.is_team:
|
|
||||||
members.append(person.name)
|
|
||||||
else:
|
|
||||||
members.append(person.name)
|
|
||||||
else:
|
|
||||||
members.append(person_or_team.name)
|
|
||||||
return members
|
|
||||||
|
|
||||||
def fetch_group_members(group_name):
|
def fetch_group_members(group_name, recurse=False):
|
||||||
try:
|
try:
|
||||||
#Try to fetch from cache first
|
#Try to fetch from cache first
|
||||||
cached_result = cache.get(f"group_members_{group_name}")
|
cached_result = cache.get(f"group_members_{group_name}")
|
||||||
|
@ -34,10 +19,10 @@ def fetch_group_members(group_name):
|
||||||
|
|
||||||
group_members = set()
|
group_members = set()
|
||||||
for person in group.members:
|
for person in group.members:
|
||||||
ext = fetch_individual_or_team_members(person, launchpad)
|
print(person)
|
||||||
if ext:
|
if not person.is_team:
|
||||||
for member in ext:
|
group_members.add(person.name)
|
||||||
group_members.add(member)
|
continue
|
||||||
|
|
||||||
# MXIDs should be generated for individuals only
|
# MXIDs should be generated for individuals only
|
||||||
print(group_members)
|
print(group_members)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
@cache_page(60 * 30) # Cache for 30 minutes
|
#@cache_page(60 * 30) # Cache for 30 minutes
|
||||||
def group_members(self, group_name):
|
def group_members(self, group_name):
|
||||||
try:
|
try:
|
||||||
result = fetch_group_members(group_name)
|
result = fetch_group_members(group_name)
|
||||||
|
|
Loading…
Reference in a new issue