Reduce sqlalchemy reflection overhead at recorder setup time (#113989)

This commit is contained in:
J. Nick Koston 2024-03-23 00:25:05 -10:00 committed by GitHub
parent 7b0abb00aa
commit de62b7774f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ from collections.abc import Iterable, Mapping
import logging import logging
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from sqlalchemy import MetaData from sqlalchemy import MetaData, Table
from sqlalchemy.exc import OperationalError from sqlalchemy.exc import OperationalError
from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm.attributes import InstrumentedAttribute from sqlalchemy.orm.attributes import InstrumentedAttribute
@ -94,9 +94,9 @@ def _validate_table_schema_has_correct_collation(
with session_scope(session=instance.get_session(), read_only=True) as session: with session_scope(session=instance.get_session(), read_only=True) as session:
table = table_object.__tablename__ table = table_object.__tablename__
metadata_obj = MetaData() metadata_obj = MetaData()
reflected_table = Table(table, metadata_obj, autoload_with=instance.engine)
connection = session.connection() connection = session.connection()
metadata_obj.reflect(bind=connection) dialect_kwargs = reflected_table.dialect_kwargs
dialect_kwargs = metadata_obj.tables[table].dialect_kwargs
# Check if the table has a collation set, if its not set than its # Check if the table has a collation set, if its not set than its
# using the server default collation for the database # using the server default collation for the database