Skip to content

Optimize N+1 query pattern in installation_repositories event handlers #93

@joshuadavidthomas

Description

@joshuadavidthomas

Both the async and sync installation_repositories event handlers have an N+1 query pattern when checking for existing repositories:

# In async_installation_repositories (src/django_github_app/events/ainstallation.py)
added = [
    Repository(
        installation=await Installation.objects.aget_from_event(event),
        repository_id=repo["id"],
        repository_node_id=repo["node_id"],
        full_name=repo["full_name"],
    )
    for repo in event.data["repositories_added"]
    # here
    if not await Repository.objects.filter(repository_id=repo["id"]).aexists()
]

# In sync_installation_repositories (src/django_github_app/events/installation.py)
added = [
    Repository(
        installation=Installation.objects.get_from_event(event),
        repository_id=repo["id"],
        repository_node_id=repo["node_id"],
        full_name=repo["full_name"],
    )
    for repo in event.data["repositories_added"]
    # and here
    if not Repository.objects.filter(repository_id=repo["id"]).exists()
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions