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

Clean up Project::update_project_aggregate_properties #880

Open
avrohomgottlieb opened this issue Sep 6, 2024 · 0 comments
Open

Clean up Project::update_project_aggregate_properties #880

avrohomgottlieb opened this issue Sep 6, 2024 · 0 comments

Comments

@avrohomgottlieb
Copy link
Contributor

Context

At the end of Project::load_metadata, after a project, its samples and its libraries have been added to the db, sample and project aggregate values are updated (samples aggregate library values, and projects aggregate sample values). Project aggregate logic is split up into two methods - Project::update_project_modality_properties and Project::update_project_aggregate_properties.

Problem or idea

We should look to optimize the Project::update_project_aggregate_properties method from a code readability perspective by pulling out the assignment of values from the for sample in self.samples.all() loop, and to assign them directly via querying for the different attribute values. The additional querying is not as performant as the current implementation of a single for loop, but the actual performance gain is negligible in our use case due the minimal set of attributes, which gives credence to a code readability optimization.

Solution or next step

    def update_project_aggregate_properties(self):
        """
        The Project and ProjectSummary models cache aggregated sample metadata.
        We need to update these after any project's sample gets added/deleted.
        """

        ...
        self.additional_metadata_keys = ", ".join(sorted(set(sample.additional_metadata_keys for sample in self.samples.all()), key=str.lower)
        self.diagnoses = ", ".join(sorted(set(sample.diagnosis for sample in self.samples.all()))
        ...

        self.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant