Any Suggestions for Workflow Improvement for Speed

Say I have three tables:

Table 1 - Buildings

  • Building Name

Table 2 - Group

  • Group Name
  • Buildings (list of Buildings)

Table 3 - Line Item

  • Building (from table 1)
  • Line Code
  • Line Name
  • Line Type

Table 4 - Output (same structure as Table 3)

I want to perform a workflow that creates a list of the Line Item Codes in Table 4, but only one of each code in the database.

So currently I:
(1) Run a search for all Line Items in the Group.
(2) Then I run a API workflow on that List
(3) The API workflow has a Step which adds a new Line Item to the Output table only when a Search for Line Items in the Output Table does not already contain that code for the Line item that the workflow is run on.

This works, but it is very slow causing it to time out before the end of the list.

I tried splitting the list up but it is still timing out, so hoping any of the brains trust here might have a different approach to the workflow they can recommend. Ignore the table/database structure as I simplified it to explain.

Maybe I can use “:unique elements” but the Line Names may be different for the same code which does not matter but I only want one of each code and the name and type does not matter so much as long as I use one of the versions of the name and type from the possible options.

Thanks in advance!

Have you looked at using the :group by function?

@patricia Thanks for the suggestion. I will try out using :group by combined with first item to see if that speeds it up at all.