griffithlab / civicpy

A python interface for the CIViC db application
MIT License
9 stars 5 forks source link

query for records by revision status #2

Closed ahwagner closed 4 years ago

ahwagner commented 6 years ago

Include a select filter function, with some predefined recipes.

Example recipe:

ahwagner commented 6 years ago

this may require a db view or new endpoint to support these queries, as the simple example query:

POST https://civicdb.org/api/variants/search/

Payload:
{
    "operator": "AND",
    "queries": [
        {
            "field": "suggested_changes_count",
            "condition": {
                "name": "is_greater_than_or_equal_to",
                "parameters": [
                    "new", 1
                ]
            }
        }
    ]
}

Takes 90 seconds to execute (and returns an 8MB response)

ahwagner commented 6 years ago

@susannasiebert would love your input on this one.

susannasiebert commented 6 years ago

Under the hood this executes the following query:

sanitized_status = ActiveRecord::Base.sanitize(parameters.shift)
having_clause = comparison(operation_type, 'COUNT(DISTINCT(suggested_changes.id))')

condition = ::Variant.select('variants.id')
    .joins("LEFT OUTER JOIN suggested_changes ON suggested_changes.moderated_id = variants.id AND suggested_changes.status = #{sanitized_status} AND suggested_changes.moderated_type = 'Variant'")
    .group('variants.id')
    .having(having_clause, *parameters.map(&:to_i)).to_sql

so yeah, it's joining the whole variants table on the suggested changes table which... is not ideal. I'm not quite sure how to improve this though.

ahwagner commented 4 years ago

Duplicate of #50