remove recursion

This commit is contained in:
Nils Büchner 2024-04-05 22:04:37 +02:00
parent 58fa73addb
commit 616564c21b
2 changed files with 7 additions and 22 deletions

View file

@ -6,23 +6,8 @@ from bugtracker.launchpad_singleton import get_launchpad
# Connect to Redis
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 to fetch from cache first
cached_result = cache.get(f"group_members_{group_name}")
@ -34,10 +19,10 @@ def fetch_group_members(group_name):
group_members = set()
for person in group.members:
ext = fetch_individual_or_team_members(person, launchpad)
if ext:
for member in ext:
group_members.add(member)
print(person)
if not person.is_team:
group_members.add(person.name)
continue
# MXIDs should be generated for individuals only
print(group_members)

View file

@ -14,7 +14,7 @@ import json
import requests
@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):
try:
result = fetch_group_members(group_name)