Slow REST API, query mysql db instead?


I'm finding that the large number of REST requests I'm making is slowing down a plugin I've created. I'd instead like to query the db for the info, but I'm having a really hard time finding the relevant information.  I'm using the guestAuth authentication, not sure if that matters or not.

My task is to find all build configurations based on a particular template, gathering the stats produced by the latest runs of these build configs, then tie that info back to their main projects under root. Via the db should I have access to this data like I do via the REST API?

The closest at all I've come was the data in the project, build_type, project_mapping and build_type_mapping tables, but that really got me nowhere in the end. For instance, once I have a list of all projects, how do I know which are the ones that come off root? Also, can I query to find which build configurations (build_types I'm assuming) are based off a particular template? Any help would be greatly appreciated.

1 comment
Comment actions Permalink
Official comment

Hi James,

I'd first look into why the REST API usage is slow in your case. The most common case for REST calls slowness is external authentication configured and sending credentials with each request. Check a way to eliminate that.


Also, there might be ways to execute less REST requests to get what you need. Like in TeamCity 9.1.x you can the projects structure via request:


and then get the last 3 builds in all the build configurations using template with id "TEMPLATE_ID"



You can even get away with a single request:


You will just need to reconstruct project's parents from the retrieved flat list of projects based on the id's of the projects and id's of the parent projects included.


As to reading the data from the database: I would not recommend following this approach. First, the data in the database is not an "open api" - it's format can change from one TeamCity version to another without any notices. Then, the settings-related data (in particular projects nesting structure and templates usage you are interested in) is just not stored in the database, as these are part of the settings stored on disk.

If REST API approach does not work for you, the only recommended approach is to write a Java (or another JVM language) plugin for TeamCity.

Please sign in to leave a comment.