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

⚡️ Speed up method AstraDBVectorStoreComponent.get_database_list_static by 12% in PR #6048 (bugfix-dev-astradb) #6084

Closed
Show file tree
Hide file tree
Changes from all 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
37 changes: 15 additions & 22 deletions src/backend/base/langflow/components/vectorstores/astradb.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,34 +310,27 @@
def get_database_list_static(cls, token: str, environment: str | None = None):
client = DataAPIClient(token=token, environment=environment)

# Get the admin object
# Get the admin object and list of databases
admin_client = client.get_admin(token=token)
db_list = admin_client.list_databases()

# Get the list of databases
db_list = list(admin_client.list_databases())

# Set the environment properly
env_string = ""
if environment and environment != "prod":
env_string = f"-{environment}"
# Set the environment suffix
env_suffix = f"-{environment}" if environment and environment != "prod" else ""

# Generate the api endpoint for each database
# Generate api endpoints and fetch collections for all databases in bulk
db_info_dict = {}
for db in db_list:
try:
api_endpoint = f"https://{db.info.id}-{db.info.region}.apps.astra{env_string}.datastax.com"
db_info_dict[db.info.name] = {
"api_endpoint": api_endpoint,
"collections": len(
list(
client.get_database(
api_endpoint=api_endpoint, token=token, keyspace=db.info.keyspace
).list_collection_names(keyspace=db.info.keyspace)
)
),
}
except Exception: # noqa: BLE001, S110
pass
db_info = db.info
api_endpoint = f"https://{db_info.id}-{db_info.region}.apps.astra{env_suffix}.datastax.com"

# Fetch collections for the database
database_client = client.get_database(api_endpoint=api_endpoint, token=token, keyspace=db_info.keyspace)
collection_names = database_client.list_collection_names(keyspace=db_info.keyspace)

db_info_dict[db_info.name] = {"api_endpoint": api_endpoint, "collections": len(collection_names)}
except Exception: # noqa: BLE001
continue

Check failure on line 333 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (S112)

src/backend/base/langflow/components/vectorstores/astradb.py:332:13: S112 `try`-`except`-`continue` detected, consider logging the exception

return db_info_dict

Expand Down
Loading
Loading