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 all 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
26 changes: 11 additions & 15 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 @@ -780,22 +781,22 @@ def get_unique_dimension_ids_from_datasets(
else:
matrix_dimension_class = DatasetSample

unique_dims = set()

# 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 +806,7 @@ 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)
}
# Combine the unique given ids from the tabular and matrix datasets
return tabular_dimension_ids.union(matrix_dimension_ids)

return unique_dims
Loading