fromcontextlibimportcontextmanagerfromtimeimporttimeimportftrack_apisession=ftrack_api.Session()@contextmanagerdeftiming(description):start=time()yieldelapsed_time=time()-startprint'{0}: {1}'.format(description,elapsed_time)deftest_link(path):link_value=u'%'.join(path)session.query(u'TypedContext where link like "%{}%"'.format(link_value)).all()deftest_parent_name(path):query=''forindex,iteminenumerate(reversed(path)):if(index>0):query+=' and 'parents='parent.'*indexquery+='{}name is "{}"'.format(parents,item)session.query(u'TypedContext where {}'.format(query)).all()deftest_ancestors(path):query=' and '.join(['ancestors any (name is "{}")'.format(name)fornameinpath])session.query(u'TypedContext where {}'.format(query)).all()deftest_parent_has(path):project=path[0]first_parent=path[1]query='name is {} and project.name is {}'.format(first_parent,project)forindex,iteminenumerate(path[2:]):query='name is {} and parent[TypedContext] has ({})'.format(item,query)session.query(u'TypedContext where {}'.format(query)).all()path=['Sync','BikeChase','Motorway-0050','Compositing']withtiming('parent has (parent has (name))'):foriinxrange(100):test_parent_has(path)withtiming('link like'):foriinxrange(100):test_link(path)withtiming('parent.parent.name'):foriinxrange(100):test_parent_name(path)withtiming('ancestors'):foriinxrange(100):test_ancestors(path)
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.