+from contextlib import contextmanager
+session = ftrack_api.Session()
+def timing(description):
+ elapsed_time = time() - start
+ print '{0}: {1}'.format(description, elapsed_time)
+ link_value = u'%'.join(path)
+ session.query(u'TypedContext where link like "%{}%"'.format(link_value)).all()
+def test_parent_name(path):
+ for index, item in enumerate(reversed(path)):
+ parents = 'parent.' * index
+ query += '{}name is "{}"'.format(parents, item)
+ session.query(u'TypedContext where {}'.format(query)).all()
+def test_ancestors(path):
+ query = ' and '.join(['ancestors any (name is "{}")'.format(name) for name in path])
+ session.query(u'TypedContext where {}'.format(query)).all()
+def test_parent_has(path):
+ query = 'name is {} and project.name is {}'.format(first_parent, project)
+ for index, item in enumerate(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']
+with timing('parent has (parent has (name))'):
+with timing('link like'):
+with timing('parent.parent.name'):
+with timing('ancestors'):