Skip to content

Commit

Permalink
use lru_cache instead of custom cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pnadolny13 committed Sep 14, 2023
1 parent 6bea818 commit 668832b
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def __init__(
"""
self._config: dict[str, t.Any] = config or {}
self._sqlalchemy_url: str | None = sqlalchemy_url or None
self._table_cols_cache: dict[str, dict[str, sqlalchemy.Column]] = {}
self._schema_cache: list = []

@property
Expand Down Expand Up @@ -593,6 +592,7 @@ def schema_exists(self, schema_name: str) -> bool:

return schema_name in self._schema_cache

@lru_cache()
def get_table_columns(
self,
full_table_name: str,
Expand All @@ -607,24 +607,20 @@ def get_table_columns(
Returns:
An ordered list of column objects.
"""
if full_table_name not in self._table_cols_cache:
_, schema_name, table_name = self.parse_full_table_name(full_table_name)
inspector = sqlalchemy.inspect(self._engine)
columns = inspector.get_columns(table_name, schema_name)

self._table_cols_cache[full_table_name] = {
col_meta["name"]: sqlalchemy.Column(
col_meta["name"],
col_meta["type"],
nullable=col_meta.get("nullable", False),
)
for col_meta in columns
if not column_names
or col_meta["name"].casefold()
in {col.casefold() for col in column_names}
}

return self._table_cols_cache[full_table_name]
_, schema_name, table_name = self.parse_full_table_name(full_table_name)
inspector = sqlalchemy.inspect(self._engine)
columns = inspector.get_columns(table_name, schema_name)

return {
col_meta["name"]: sqlalchemy.Column(
col_meta["name"],
col_meta["type"],
nullable=col_meta.get("nullable", False),
)
for col_meta in columns
if not column_names
or col_meta["name"].casefold() in {col.casefold() for col in column_names}
}

def get_table(
self,
Expand Down

0 comments on commit 668832b

Please sign in to comment.