Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get active installations method #2134

Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions thoth/storages/graph/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,17 @@ def update_kebechet_github_installations_on_is_active(self, slug: str) -> bool:
return True
return False

def get_active_kebechet_github_installations_repos(self) -> Dict[str, List[str]]:
"""Get all active repositories names with active Kebechet installation."""
xtuchyna marked this conversation as resolved.
Show resolved Hide resolved
with self._session_scope() as session:
active_installations = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xtuchyna you can also use directly with_entities to receive directly the specific parameter.

active_installations_repos = (
     session.query(KebechetGithubAppInstallations)
     .filter(KebechetGithubAppInstallations.is_active.is_(True))
     .with_entities(KebechetGithubAppInstallations.slug)
     .all()
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better to do on the database side to avoid unnecessary serialization, rather than in python code.

session.query(KebechetGithubAppInstallations)
.filter(KebechetGithubAppInstallations.is_active.is_(True))
.all()
)
xtuchyna marked this conversation as resolved.
Show resolved Hide resolved

return { i.slug:self.get_kebechet_github_installations_active_managers(slug=i.slug) for i in active_installations }
xtuchyna marked this conversation as resolved.
Show resolved Hide resolved

def get_kebechet_github_installations_count_per_is_active(self) -> int:
"""Return the count of active repos with Kebechet installation."""
with self._session_scope() as session:
Expand Down