Jump to content

Quick way to grab structure of entire Project?


Recommended Posts

Is there a quick way (both in terms of code I have to write and in terms of DB time) to grab the whole structure of a project as a dict, perhaps with some fields projected? I'd like to present a view of a project to select where to publish some versions in a tree view or similar.

Link to comment
Share on other sites

Hi Alan,

Are we talking about a tree widget where you expand portions and drill down to leaves?

If you don't know or have a sense of the scale of the project, it might be a costly operation to load everything initially. A past strategy I've used is to load the top node and its children first. Then I'd start one or multiple threads to load children based on a priority that makes sense (top node displayed on screen first, if a node is expanded, prioritize the children in that node, etc...).

This would basically preload items quickly enough that the user wouldn't get much latency when navigating the tree. Of course, this comes at the expense of more API requests with each being lighter than a full request.

If you do want to do it in as few calls as possible, you could do the following or similar:

items = session.query(
    f"select name, object_type.name from TypedContext where parent_id = {prj_id} or ancestors any (parent_id = {prj_id})"

This would imply 2 calls. One for the project itself, but you might already have a handle on that, and one for the objects under it. This will give you unordered data that you can then put in a tree.


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...