0

query efficiency

Hello,

 

Fairly new to Shotgun, and I have a question about queries:

I am querying for element versions matching specific filters.  That works fine, but when I hit a sequence with a lot of shots... things slow down (e.g. 45sec. wait period for result).  I searched the forum for related information, but I could not get anything that would help me with my approach.


How should I go about improving response time?  What do people do when they deal with a big query?  What is the best way to cut it down to get a better and more interactive response?

 

Any pointer is welcome, as the dumb way works but does not seem too efficient. :)

 

Cheers,

nico

2 comments

  • 0
    Avatar
    Isaac Reuben

    Hey Nico,

    If you want to post the series of queries you are doing now, we can take a stab at how you could make them faster.  The key thing is usually making less queries, since each query has to go to the server and back to get a response.  So if you can make one query that gets all of the info you want, the total time will usually be much faster.

    Cheers,

    - Isaac

  • 0
    Avatar
    Nico Dufort

    Hi Isaac,

    This is part of what I am doing.  I will admit that my first problem is how to approach this. :)

    At first, I would query a sequence, and then filter out shots based on some criteria, and extract frame range info, to eventually get down to elements and versions level.  I was then showed how to go directly to Elements/Versions level to get what I wanted.  That's all good but that does not provide me with all the info I was saving by going through my original approach, and I will need to re-query it separately.


    The following gets me Elements and Versions lists.  I'm not convinced by the way I chose to go about it.  It works, but on a  sequence with a lot of shots, it seems slow.  I was told that it did not matter for the purpose of the tool, but I was curious if I could get some good advice to think efficiently about querying Shotgun data.


    Any advice is welcome!

    Thanks. nico


    def get_sg_elements(job, sequence):

        job_id = sg.find_one('Project', [['name', 'is', job]])['id']
        filters = [['project', 'is', {'type':'Project', 'id':job_id}],
                      ['code', 'starts_with', sequence],
                      ['sg_description', 'is', 'Blah'],
                      ['sg_element_type', 'is', 'plate'],
                      ['sg_status_list', 'is', 'act']]
        return sg.find('Element', filters, ['code'])

    def get_sg_versions(element):
        filters = [['code', 'ends_with', 'FOO'],
                      ['entity', 'name_contains', element['code']]]
        fields = ['code', 'sg_path_to_movie']
        return sg.find_one('Version', filters, fields)

     

    sg_elements = get_sg_elements(args.job, args.seq)

    sg_versions = [get_sg_versions(element) for element in sg_elements]

Please sign in to leave a comment.