griffithlab / civic-v2

CIViC is an open access, open source, community-driven web resource for Clinical Interpretation of Variants in Cancer
https://civicdb.org
MIT License
19 stars 5 forks source link

Add a Materialized View to support the Organization browse table #1073

Closed acoffman closed 2 months ago

acoffman commented 3 months ago

Right now, we are directly using the Organization activerecord model, this means its not possible (or performant) to do things like sort on most recent event, activity count, or user count.

We should create a view that performs this aggregation in postgres.

This view should select all of the existing fields on the organizations table along with member count, event count, and the ids and names of any child organizations.

Event count can be gotten by joining to the activities table, member count by joining to the users table and child organizations can be retrieved by selecting from the organizations table where parent_id matches id.

Roughly, you will need to

Once that's completed you should be able to open up a rails console with rails c and run MaterializedViews::OrganizationBrowseTableRow.first and have it return a value. Then we can work on making this new model available via the API.