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

bug: graphql node query with only count field is slow when you have a large number of this kind of node in the database #4454

Closed
wvandeun opened this issue Sep 25, 2024 · 1 comment
Assignees
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected

Comments

@wvandeun
Copy link
Contributor

Component

API Server / GraphQL

Infrahub version

0.16.0

Current Behavior

Executing the following GraphQL query is really slow (several minutes) , when you have 3k instances of InfraInterfaceL2 in the database

query {
  InfraInterfaceL2 {
    count
  }
}

Executing the same query, adding one additional field (attribute of the node) resolves instantly:

query {
  InfraInterfaceL2 {
    count
    edges {
      node {
        id
      }
    }
  }
}

Expected Behavior

A GraphQL query using just the count field for a particular node, should resolve much faster.

Steps to Reproduce

  • load infrahub instance with demo schema inv dev.start demo.load-infra-schema
  • load data into the system with this script infrahubctl run <script.py>
import logging
from infrahub_sdk import InfrahubClient


async def run(client: InfrahubClient, log: logging.Logger, branch: str, num_devices: int=30) -> None:
    site = await client.create("LocationSite", name="atl1")
    await site.save(allow_upsert=True)

    num_devices = int(num_devices)

    device_batch = await client.create_batch()
    interface_batch = await client.create_batch()

    for i in range(num_devices):
        device = await client.create("InfraDevice", name=f"atl1-test{i}", site=site, type="testing")
        device_batch.add(task=device.save, node=device, allow_upsert=True)
        log.info(f"Added device {device.name.value}")
        
    async for node, result in device_batch.execute():
        print(f"device {node.name.value} was created in Infrahub succesfully")
        client.store.set(key=node.name.value, node=node)

    for i in range(num_devices):
        for j in range(100):
            interface = await client.create("InfraInterfaceL2", name=f"Ethernet{j}", l2_mode="Access", speed=10000, device=client.store.get(key=f"atl1-test{i}"))
            interface_batch.add(task=interface.save, node=interface, allow_upsert=True)
            log.info(f"  Added interface {interface.name.value} for device {interface.device.peer.name.value}")

    async for node, result in interface_batch.execute():
        print(f"interface {node.name.value} {node.device.peer.name.value} was created in Infrahub succesfully")
  • execute the following GraphQL query
query {
  InfraInterfaceL2 {
    count
  }
}

Additional Information

No response

@wvandeun wvandeun added type/bug Something isn't working as expected group/backend Issue related to the backend (API Server, Git Agent) labels Sep 25, 2024
@exalate-issue-sync exalate-issue-sync bot added this to the Infrahub - 0.16.2 milestone Sep 25, 2024
@exalate-issue-sync exalate-issue-sync bot removed the group/backend Issue related to the backend (API Server, Git Agent) label Sep 25, 2024
@exalate-issue-sync exalate-issue-sync bot removed this from the Infrahub - 0.16.2 milestone Sep 25, 2024
@exalate-issue-sync exalate-issue-sync bot added the group/backend Issue related to the backend (API Server, Git Agent) label Sep 25, 2024
@exalate-issue-sync exalate-issue-sync bot added this to the Infrahub - 0.16.2 milestone Sep 25, 2024
@ogenstad ogenstad self-assigned this Sep 25, 2024
ogenstad added a commit that referenced this issue Sep 25, 2024
ogenstad added a commit that referenced this issue Sep 26, 2024
@ogenstad
Copy link
Contributor

Fixed in #4459.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants