Skip to content

Commit

Permalink
feat(publicBrains): use join queries for better performance (#1730)
Browse files Browse the repository at this point in the history
Issue #1720
  • Loading branch information
mamadoudicko authored Nov 27, 2023
1 parent 914e5b2 commit f1ddaca
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions backend/models/databases/supabase/brains.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@ def get_user_brains(self, user_id) -> list[MinimalBrainEntity]:
def get_public_brains(self) -> list[PublicBrain]:
response = (
self.db.from_("brains")
.select("id:brain_id, name, description, last_update, brain_type")
.select(
"id:brain_id, name, description, last_update, brain_type, brain_definition: api_brain_definition(*), number_of_subscribers:brains_users(count)"
)
.filter("status", "eq", "public")
.execute()
)
public_brains: list[PublicBrain] = []

for item in response.data:
brain = PublicBrain(
id=item["id"],
name=item["name"],
description=item["description"],
last_update=item["last_update"],
brain_type=item["brain_type"],
brain_definition=self.get_api_brain_definition(item["id"]),
)
brain.number_of_subscribers = self.get_brain_subscribers_count(brain.id)
public_brains.append(brain)
item["number_of_subscribers"] = item["number_of_subscribers"][0]["count"]
if not item["brain_definition"]:
del item["brain_definition"]
else:
item["brain_definition"] = item["brain_definition"][0]
item["brain_definition"]["secrets"] = []

public_brains.append(PublicBrain(**item))
return public_brains

def update_brain_last_update_time(self, brain_id: UUID) -> None:
Expand Down

0 comments on commit f1ddaca

Please sign in to comment.