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

Optimize homepage load #1210

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions nmdc_server/migrations/versions/613956d85ada_index_study_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""index-study-id

Revision ID: 613956d85ada
Revises: b4b234bd55cf
Create Date: 2024-04-11 19:33:18.337288

"""

from typing import Optional

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "613956d85ada"
down_revision: Optional[str] = "b4b234bd55cf"
branch_labels: Optional[str] = None
depends_on: Optional[str] = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f("ix_biosample_id"), "biosample", ["id"], unique=False)
op.create_index(op.f("ix_biosample_study_id"), "biosample", ["study_id"], unique=False)
op.create_index(op.f("ix_omics_processing_id"), "omics_processing", ["id"], unique=False)
op.create_index(
op.f("ix_omics_processing_study_id"), "omics_processing", ["study_id"], unique=False
)
op.create_index(op.f("ix_study_id"), "study", ["id"], unique=False)
op.create_unique_constraint(
op.f("uq_submission_role_submission_id"), "submission_role", ["submission_id", "user_orcid"]
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(op.f("uq_submission_role_submission_id"), "submission_role", type_="unique")
op.drop_index(op.f("ix_study_id"), table_name="study")
op.drop_index(op.f("ix_omics_processing_study_id"), table_name="omics_processing")
op.drop_index(op.f("ix_omics_processing_id"), table_name="omics_processing")
op.drop_index(op.f("ix_biosample_study_id"), table_name="biosample")
op.drop_index(op.f("ix_biosample_id"), table_name="biosample")
# ### end Alembic commands ###
6 changes: 3 additions & 3 deletions nmdc_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class DOIInfo(Base):


class AnnotatedModel:
id = Column(String, primary_key=True)
id = Column(String, primary_key=True, index=True)
name = Column(String, nullable=False)
description = Column(String, nullable=False, default="")

Expand Down Expand Up @@ -312,7 +312,7 @@ class Biosample(Base, AnnotatedModel):
latitude = Column(Float, nullable=True)
longitude = Column(Float, nullable=True)

study_id = Column(String, ForeignKey("study.id"), nullable=False)
study_id = Column(String, ForeignKey("study.id"), nullable=False, index=True)
multiomics = Column(Integer, nullable=False, default=0)
emsl_biosample_identifiers = Column(JSONB, nullable=True)
omics_processing = relationship(
Expand Down Expand Up @@ -367,7 +367,7 @@ class OmicsProcessing(Base, AnnotatedModel):
biosample_inputs = relationship(
"Biosample", secondary=biosample_input_association, back_populates="omics_processing"
)
study_id = Column(String, ForeignKey("study.id"), nullable=True)
study_id = Column(String, ForeignKey("study.id"), nullable=True, index=True)
study = relationship("Study", backref="omics_processing")

outputs = output_relationship(omics_processing_output_association)
Expand Down
2 changes: 1 addition & 1 deletion nmdc_server/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ class BinnedDateFacetQuery(FacetQuery):


class StudySearchResponse(BaseSearchResponse):
results: List[schemas.Study]
results: List[schemas.StudyBase]
total: Optional[int]


Expand Down
63 changes: 33 additions & 30 deletions nmdc_server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,58 +224,61 @@ class Config:
orm_mode = True


class OmicsCounts(BaseModel):
type: str
count: int

@validator("count", pre=True, always=True)
def insert_zero(cls, v):
return v or 0


class StudyBase(AnnotatedBase):
principal_investigator_websites: Optional[List[str]] = []
gold_name: str = ""
gold_description: str = ""
scientific_objective: str = ""
add_date: Optional[DateType]
mod_date: Optional[DateType]
has_credit_associations: Optional[List[CreditAssociation]]
relevant_protocols: Optional[List[str]]
funding_sources: Optional[List[str]]
gold_study_identifiers: Optional[List[str]]
homepage_website: Optional[List[str]]
part_of: Optional[List[str]]
study_category: Optional[str]
children: Optional[List[Study]] = []
children: Optional[List[StudyBase]] = []
sample_count: Optional[int]
omics_counts: Optional[List[OmicsCounts]]
omics_processing_counts: Optional[List[OmicsCounts]]
multiomics: int

@validator("principal_investigator_websites", pre=True, each_item=True)
def replace_websites(cls, study_website: Union[models.StudyWebsite, str]) -> str:
if isinstance(study_website, str):
return study_website
return study_website.website.url
class Config:
orm_mode = True


class StudyCreate(StudyBase):
principal_investigator_id: Optional[UUID]
image: Optional[bytes]


class OmicsCounts(BaseModel):
type: str
count: int

@validator("count", pre=True, always=True)
def insert_zero(cls, v):
return v or 0


class Study(StudyBase):
principal_investigator_websites: Optional[List[str]] = []
gold_name: str = ""
gold_description: str = ""
scientific_objective: str = ""
add_date: Optional[DateType]
mod_date: Optional[DateType]
has_credit_associations: Optional[List[CreditAssociation]]
relevant_protocols: Optional[List[str]]
funding_sources: Optional[List[str]]
gold_study_identifiers: Optional[List[str]]
homepage_website: Optional[List[str]]
open_in_gold: Optional[str]
principal_investigator: Optional[OrcidPerson]
principal_investigator_name: Optional[str]
image_url: str
principal_investigator_image_url: str
sample_count: Optional[int]
omics_counts: Optional[List[OmicsCounts]]
omics_processing_counts: Optional[List[OmicsCounts]]
doi_map: Dict[str, Any] = {}
multiomics: int

class Config:
orm_mode = True

@validator("principal_investigator_websites", pre=True, each_item=True)
def replace_websites(cls, study_website: Union[models.StudyWebsite, str]) -> str:
if isinstance(study_website, str):
return study_website
return study_website.website.url


# biosample
class BiosampleBase(AnnotatedBase):
Expand Down
Loading