Jump to content

Faster querying


Jakub Trllo

Recommended Posts

Hi,

I have a question: Is there any faster possibility of getting all entities from project than with code below?
```PYTHON
# ft_project_id - Project's ID
entities_query = (
    "select id, name, parent_id, link, custom_attributes"
    " from TypedContext where project_id is \"{}\""
)
all_project_entities = session.query(
    entities_query.format(ft_project_id)
).all()
```

It's actually pretty fast (0.027s/entity) but with 4500 entities in project it takes 2 minutes.

EDITED:

Found out that when custom_attributes are not in query it is much faster (from 2 minutes -> 6 seconds), so it was my fault.

Thanks,

Jakub

Link to comment
Share on other sites

On 11/5/2019 at 9:12 AM, JPrydz said:

Hi Jakub,

Thanks for updating the thread.

Regards
Johan

Hi,

I'll extend the question. Is possible to set custom attributes for multiple entities at once?

ISSUE:
I have dictionary where key represents id of ftrack entity and value represents a value of one specific custom attribute. I would like to set them all at once (or as fast as possible in other words).

NOTE:
I have also ftrack entities at the moment I need to change values of the custom attribute. But when I'll use `entity["custom_attributes"]["{specific_key}"] = value` to change value it takes on average 0,2 second (60 seconds for whole project). It's probably because every time is used `custom_attributes` key on entity, api is querying values of custom attributes? I assume that it is not possible to use UPDATE of INSERT queries, right?

Thanks,

Jakub

EDITED:

Found out that session has recorded_operations where I can put UpdateEntityOperation.  With this it takes less then 0.1 for whole project, GREAT :)  Is this usage "kosher"?

Link to comment
Share on other sites

Hi @Jakub Trllo, you have almost answered yourself the question:
>> It's probably because every time is used `custom_attributes` key on entity, api is querying values of custom attributes?

It is quite possible that is what causing your slowdown.
If you don't need / care about what the previous value was you can think of turning off the auto_popluate using the context manager for it.
You can find further information here.

Let us know how it goes!

L.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...