Skip to content

Commit

Permalink
rename some things for clarity and to also avoid rebinding variable w…
Browse files Browse the repository at this point in the history
…ith different type for mypy's sake
  • Loading branch information
tkaemming committed Dec 6, 2024
1 parent b3bcd26 commit 4abd569
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions ee/clickhouse/materialized_columns/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _analyze(since_hours_ago: int, min_query_time: int, team_id: Optional[int] =


def materialize_properties_task(
columns_to_materialize: Optional[list[Suggestion]] = None,
properties_to_materialize: Optional[list[Suggestion]] = None,
time_to_analyze_hours: int = MATERIALIZE_COLUMNS_ANALYSIS_PERIOD_HOURS,
maximum: int = MATERIALIZE_COLUMNS_MAX_AT_ONCE,
min_query_time: int = MATERIALIZE_COLUMNS_MINIMUM_QUERY_TIME,
Expand All @@ -178,18 +178,18 @@ def materialize_properties_task(
Creates materialized columns for event and person properties based off of slow queries
"""

if columns_to_materialize is None:
columns_to_materialize = _analyze(time_to_analyze_hours, min_query_time, team_id_to_analyze)
if properties_to_materialize is None:
properties_to_materialize = _analyze(time_to_analyze_hours, min_query_time, team_id_to_analyze)

columns_by_table: dict[TableWithProperties, list[tuple[TableColumn, PropertyName]]] = defaultdict(list)
for table, table_column, property_name in columns_to_materialize:
columns_by_table[table].append((table_column, property_name))
properties_by_table: dict[TableWithProperties, list[tuple[TableColumn, PropertyName]]] = defaultdict(list)
for table, table_column, property_name in properties_to_materialize:
properties_by_table[table].append((table_column, property_name))

result: list[Suggestion] = []
for table, columns in columns_by_table.items():
existing_materialized_columns = get_materialized_columns(table)
for table, columns in properties_by_table.items():
existing_materialized_properties = get_materialized_columns(table).keys()
for table_column, property_name in columns:
if (property_name, table_column) not in existing_materialized_columns:
if (property_name, table_column) not in existing_materialized_properties:
result.append((table, table_column, property_name))

if len(result) > 0:
Expand Down
2 changes: 1 addition & 1 deletion ee/management/commands/materialize_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def handle(self, *, is_nullable: bool, **options):
logger.info(f"Materializing column. table={options['property_table']}, property_name={options['property']}")

materialize_properties_task(
columns_to_materialize=[
properties_to_materialize=[
(
options["property_table"],
options["table_column"],
Expand Down

0 comments on commit 4abd569

Please sign in to comment.