Description
In db.utils, improve get_declaring_class by avoiding the iteration over all the registry mappers, to make this function more efficient, since it's called in many endpoints.
Current code:
|
def get_declaring_class[I: Identifiable]( |
|
db_model_class: type[I], column_name: str |
|
) -> type[I] | None: |
|
"""Return the class that has a table with project id or None.""" |
|
if not has_project_id_in_columns(db_model_class): |
|
return None |
|
|
|
declaring_table = db_model_class.__mapper__.columns[column_name].table |
|
|
|
# Iterate all mappers registered with the Base registry |
|
for mapper in db_model_class.registry.mappers: |
|
if mapper.local_table is declaring_table: |
|
return mapper.class_ |
|
|
|
return None |
Acceptance criteria
Description
In db.utils, improve get_declaring_class by avoiding the iteration over all the registry mappers, to make this function more efficient, since it's called in many endpoints.
Current code:
entitycore/app/db/utils.py
Lines 190 to 204 in 01236ce
Acceptance criteria