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

perf(breadbox): Small breadbox performance tweak #214

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Changes from 2 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
21 changes: 10 additions & 11 deletions breadbox/breadbox/crud/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pandas as pd
from sqlalchemy import and_, func, or_
from sqlalchemy.sql import distinct
from sqlalchemy.orm import aliased, with_polymorphic

from breadbox.db.session import SessionWithUser
Expand Down Expand Up @@ -783,19 +784,21 @@ def get_unique_dimension_ids_from_datasets(
unique_dims = set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can remove this with your changes!


# Get all matrix dimensions for that dimension type
matrix_dimensions = (
db.query(matrix_dimension_class)
matrix_dimension_ids = {
given_id for (given_id,) in
db.query(distinct(matrix_dimension_class.given_id))
.filter(
and_(
Dimension.dataset_id.in_(dataset_ids),
Dimension.dataset_dimension_type == dimension_type.name,
)
)
.all()
)
}
# Get all tabular identifiers for that dimension type
tabular_dimension_ids = (
db.query(TabularCell)
tabular_dimension_ids = {
given_id for (given_id,) in
db.query(distinct(TabularCell.dimension_given_id))
.join(TabularColumn)
.filter(
and_(
Expand All @@ -805,12 +808,8 @@ def get_unique_dimension_ids_from_datasets(
)
)
.all()
)
}
# Combine dimension type's dimension given ids from datasets
for m_dim in matrix_dimensions:
unique_dims.add(m_dim.given_id)

for t_dim in tabular_dimension_ids:
unique_dims.add(t_dim.dimension_given_id)
unique_dims = tabular_dimension_ids.union(matrix_dimension_ids)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


return unique_dims
Loading