Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

Commit f747827

Browse files
improve performance for wallet querying
1 parent 8a5d014 commit f747827

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

app/api/profiles.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,27 @@ async def get_all_profile_addresses(
9292
dao = daos[0]
9393
logger.debug(f"Found DAO: {dao.name} (ID: {dao.id})")
9494

95-
# Get agents associated with this DAO
96-
all_agents = backend.list_agents(AgentFilter())
97-
dao_agents = []
98-
99-
for agent in all_agents:
100-
if agent.profile_id:
101-
# Check if this agent has holders associated with the DAO
102-
holders = backend.list_holders(
103-
HolderFilter(dao_id=dao.id, agent_id=agent.id)
104-
)
105-
if holders:
106-
dao_agents.append(agent.id)
107-
108-
logger.debug(f"Found {len(dao_agents)} agents for DAO: {dao_name}")
95+
# Get all holders for this DAO
96+
holders = backend.list_holders(HolderFilter(dao_id=dao.id))
97+
holder_addresses = {holder.address for holder in holders if holder.address}
98+
99+
logger.debug(
100+
f"Found {len(holder_addresses)} unique holder addresses for DAO: {dao_name}"
101+
)
102+
103+
# Get agents whose account_contract matches a holder address
104+
if holder_addresses:
105+
# Use the efficient batch filtering
106+
filtered_agents = backend.list_agents(
107+
AgentFilter(account_contracts=list(holder_addresses))
108+
)
109+
dao_agents = [agent.id for agent in filtered_agents]
110+
else:
111+
dao_agents = []
112+
113+
logger.debug(
114+
f"Found {len(dao_agents)} agents holding tokens for DAO: {dao_name}"
115+
)
109116

110117
result = []
111118

app/backend/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ class QueueMessageFilter(CustomBaseModel):
625625
class AgentFilter(CustomBaseModel):
626626
profile_id: Optional[UUID] = None
627627
account_contract: Optional[str] = None
628+
account_contracts: Optional[List[str]] = (
629+
None # Batch filter for multiple account contracts
630+
)
628631

629632

630633
class ExtensionFilter(CustomBaseModel):

app/backend/supabase.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,11 @@ def list_agents(self, filters: Optional["AgentFilter"] = None) -> List["Agent"]:
955955
query = query.eq("profile_id", str(filters.profile_id))
956956
if filters.account_contract is not None:
957957
query = query.eq("account_contract", filters.account_contract)
958+
if (
959+
filters.account_contracts is not None
960+
and len(filters.account_contracts) > 0
961+
):
962+
query = query.in_("account_contract", filters.account_contracts)
958963
response = query.execute()
959964
data = response.data or []
960965
return [Agent(**row) for row in data]

0 commit comments

Comments
 (0)