<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/discussions/f/user-interface/20166/optimize-interface-code-so-that-the-queryentity-is-called-as-minimal-as-possible</link><description>Hi All, 
 i have written an interface code , which calls an query entity multiple time , because of which sometimes am facing Query timeout issue, Please help me in Optimizing the code 
 with( a!localVariables( local!dcSelectedrole : ri!dcSelectedRole</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78773?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 14:29:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3180eae8-7651-49bc-b4f8-04a2c040b01e</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;You can use the &amp;quot;in&amp;quot; operator rather than the &amp;quot;=&amp;quot; operator for the queryFilter on the field &amp;quot;typevalue&amp;quot;. You&amp;#39;ll have to make sure that&amp;nbsp;ri!typeValue is an array so you can pass in multiple values.&lt;/p&gt;
&lt;p&gt;Again, an observation: you are essentially constructing the same Query Entity based upon different if() conditions. You could make a single Query Entity, use the incoming value of ri!roleType to select the relevant entity cons!, and then use the &amp;#39;&lt;span&gt;applyWhen&amp;#39; in the filters that only apply conditionally. This will make the code more maintainable&amp;nbsp;and easier to read.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78772?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 13:07:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6d2e4df9-ba6f-4e1e-a7fa-1fd73cbae6dd</guid><dc:creator>vineethk0001</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if(ri!roleType = &amp;quot;SuperAdmin&amp;quot;,
    a!queryEntity(
      entity: cons!CMP_CHART_PROGRAM_CONS,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: &amp;quot;AND&amp;quot;,
          filters: {
            a!queryFilter(
              field: &amp;quot;programid&amp;quot;,
              operator: &amp;quot;=&amp;quot;,
              value: ri!programID
            ),
            a!queryFilter(
              field: &amp;quot;type&amp;quot;,
              operator: &amp;quot;=&amp;quot;,
              value: ri!type
            ),
            a!queryFilter(
              field: &amp;quot;typevalue&amp;quot;,
              operator: &amp;quot;=&amp;quot;,
              value: ri!typeValue
            ),
          }
        ),
        pagingInfo: a!pagingInfo(startIndex: 1,batchSize: -1)
      ),
      fetchTotalCount: true
    ).data,
    if(ri!roleType = &amp;quot;CL&amp;quot;,
        a!queryEntity(
          entity: cons!CMP_CHART_SBG_CONS,
          query: a!query(
            logicalExpression: a!queryLogicalExpression(
              operator: &amp;quot;AND&amp;quot;,
              filters: {
                a!queryFilter(
                  field: &amp;quot;programid&amp;quot;,
                  operator: &amp;quot;=&amp;quot;,
                  value: ri!programID
                ),
                a!queryFilter(
                  field: &amp;quot;type&amp;quot;,
                  operator: &amp;quot;=&amp;quot;,
                  value: ri!type
                ),
                a!queryFilter(
                  field: &amp;quot;typevalue&amp;quot;,
                  operator: &amp;quot;=&amp;quot;,
                  value: ri!typeValue
                ),
                a!queryFilter(
                  field: &amp;quot;sbg&amp;quot;,
                  operator: &amp;quot;=&amp;quot;,
                  value: ri!sbg
                ),
    
    
              }
            ),
            pagingInfo:  a!pagingInfo(startIndex: 1,batchSize: -1)
          ),
          fetchTotalCount: true
        ),
        if(ri!roleType = &amp;quot;NOM&amp;quot;,
              a!queryEntity(
                entity: cons!CMP_CHART_NOMINATOR_CONS,
                query: a!query(
                  logicalExpression: a!queryLogicalExpression(
                    operator: &amp;quot;AND&amp;quot;,
                    filters: {
                      a!queryFilter(
                        field: &amp;quot;programid&amp;quot;,
                        operator: &amp;quot;=&amp;quot;,
                        value: ri!programID
                      ),
                      a!queryFilter(
                        field: &amp;quot;type&amp;quot;,
                        operator: &amp;quot;=&amp;quot;,
                        value: ri!type
                      ),
                      a!queryFilter(
                        field: &amp;quot;typevalue&amp;quot;,
                        operator: &amp;quot;=&amp;quot;,
                        value: ri!typeValue
                      ),
                      a!queryFilter(
                        field: &amp;quot;nominatoreid&amp;quot;,
                        operator: &amp;quot;=&amp;quot;,
                        value: ri!nominatorEID
                      ),
      
      
                    }
                  ),
                  pagingInfo: a!pagingInfo(startIndex: 1,batchSize: -1)
                ),
                fetchTotalCount: true
              ),
              if(ri!roleType = &amp;quot;HRG&amp;quot;,
                    a!queryEntity(
                      entity: cons!CMP_CHART_HRG_CONS,
                      query: a!query(
                        logicalExpression: a!queryLogicalExpression(
                          operator: &amp;quot;AND&amp;quot;,
                          filters: {
                            a!queryFilter(
                              field: &amp;quot;programid&amp;quot;,
                              operator: &amp;quot;=&amp;quot;,
                              value: ri!programID
                            ),
                            a!queryFilter(
                              field: &amp;quot;type&amp;quot;,
                              operator: &amp;quot;=&amp;quot;,
                              value: ri!type
                            ),
                            a!queryFilter(
                              field: &amp;quot;typevalue&amp;quot;,
                              operator: &amp;quot;=&amp;quot;,
                              value: ri!typeValue
                            ),
                            a!queryFilter(
                              field: &amp;quot;hrgeid&amp;quot;,
                              operator: &amp;quot;=&amp;quot;,
                              value: ri!hrgeid
                            ),
      
      
                          }
                        ),
                        pagingInfo: a!pagingInfo(startIndex: 1,batchSize: -1)
                      ),
                      fetchTotalCount: true
                    ),  
                    null
              )
        )
    )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have attached the code , thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78771?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 13:05:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:07caa5a4-12c8-47ca-b25d-0f2a7ef26005</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;If you send me the code for rule!CMP_getChartDataprogramLevel() I can show you what I mean&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78770?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 13:03:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3f7c1c5f-c854-4fab-a2c5-b482f80e4fa1</guid><dc:creator>vineethk0001</dc:creator><description>&lt;p&gt;Can you please suggest an example&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78769?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 12:37:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b4f6a5d5-ab9b-4f64-97a3-fc26603f7fa4</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Your Query Entity needs to be altered to allow the queryFilter to use a list of values for &amp;#39;typeValue&amp;#39;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78768?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 12:35:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ec83c680-0bcf-4f38-af63-0e26688ab7ce</guid><dc:creator>vineethk0001</dc:creator><description>&lt;p&gt;Hi Stewart, thanks for the reply, Sorry the Insert code was not working , so have put the code in the body,&lt;/p&gt;
&lt;p&gt;using the code example above, am getting the output as List of Variants - 0&lt;/p&gt;
&lt;p&gt;but both typevalue 1 and 2 has values, but if I put it together, it gives 0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Optimize interface code so that the queryentity is called as minimal as possible</title><link>https://community.appian.com/thread/78766?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 10:22:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c137399d-f9ff-4477-9e94-a84b463b1051</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Hi Vineeth&lt;/p&gt;
&lt;p&gt;Firstly, for future reference please use the &amp;#39;Insert Code&amp;#39; option (under the ;Insert&amp;#39; menu) to add code to these discussions, it retains the formatting and makes it easier for others to review, and copy (if we want to load your code into our own Interface Designer)&lt;/p&gt;
&lt;p&gt;A few observations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;this code is way too large and complex. All except one of the 37 local!&amp;nbsp; variables defined are conditional i.e. they have an if() statement around them. Since the if() is handling whether the values of&amp;nbsp;relevant parameters are blank can you not implement this logic inside the rule!CMP_getChartDataprogramLevel() ?&lt;/li&gt;
&lt;li&gt;the a!progressBarField() implementation logic looks to me to be the same but with different data - this would benefit from being refactored/abstracted into its own rule&lt;/li&gt;
&lt;li&gt;the same can be apllied to the a!richTextDisplayField() - this is also the same each time, but with different data so could become its own parameterised rule &lt;strong&gt;HINT&lt;/strong&gt;: &lt;em&gt;if you find yourself copying/pasting code fragments inside an Interface or Expression Rule and changing values without changing the structure/implementation then that indicates it should be extracted into its own component&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;I presume the Query Entity is embedded in the rule!CMP_getChartDataprogramLevel() which you are calling 36 times. You may find it better to call this rule once for every combination of the rule inputs across your 36 calls, and then extract the relevant data from the one local! variable. If that&amp;#39;s too complicated you could find common groupings of the data and reduce the calls to a smaller number e.g.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;rule!CMP_getChartDataprogramLevel(
        roleType: &amp;quot;SuperAdmin&amp;quot;,
        programId: ri!programId,
        type: &amp;quot;POC&amp;quot;,
        typeValue: {&amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;}
      ).data&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;...and then you can separate the two tranches of data from one local! variable and save yourself a call to the database.&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I also notice you&amp;#39;re wrapping the entire implementation in&amp;nbsp; a with(). This means ALL of your local! variables will be reloaded, even if they don&amp;#39;t need to be e.g. if the value of ri!sbg changes, only those local! variables that are loaded&amp;nbsp;from calls to rule!CMP_getChartDataprogramLevel() that use ri!sbg should be re-loaded. The others can retain the data they&amp;#39;ve already been loaded with. You can use the a!refreshVariable() to control what gets re-loaded under which changes in ri! values&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>