Skip to content

Commit

Permalink
perf(breadbox): Small breadbox performance tweak (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
snwessel authored Mar 10, 2025
1 parent c366885 commit c5debd8
Showing 1 changed file with 11 additions and 15 deletions.
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

0 comments on commit c5debd8

Please sign in to comment.