Skip to main content
Question

Performance issue in Custom selector attribute


Good day, everyone.


We customized a requisition (RQ302000) screen Ref Nbr. Selector to load data based on a logged in user's user role.

The selector worked fine when there were few records, but now we have thousands of records and every field on the screen takes time to update the value because of this custom selector.

The code for the custom selector is shown below. What is the best way to avoid this performance problem, and what changes should we make to this custom selector?

 

public class RequisitionEntryRQNbrExt : PXGraphExtension<RQRequisitionEntry>
    {
        #region Ref nbr attribute override
        [PXMergeAttributes(Method = MergeMethod.Append)]
        [PXRemoveBaseAttribute(typeof(PXSelectorAttribute))]
        [RQRequisitionRestrictExt]
        protected virtual void RQRequisition_ReqNbr_CacheAttached(PXCache cache)
        {

        }
        public class RQRequisitionRestrictExt : PXCustomSelectorAttribute
        {
            public RQRequisitionRestrictExt()
                : base(typeof(RQRequisition.reqNbr))
            {
                this.DescriptionField = typeof(RQRequisition.description);
            }
            protected virtual IEnumerable GetRecords()
            {
                var graph = this._Graph;
                //PXCache cache = null;

                //if (graph != null)
                //{
                //    cache = _Graph.GetPrimaryCache();
                //}

                //if (cache == null)
                //{
                //    yield break;
                //}

               UsersInRoles roleaccess = PXSelect<
                    UsersInRoles,
                    Where2<
                        Where<UsersInRoles.username, Equal<Required<AccessInfo.userName>>>,
                        And<Where<UsersInRoles.rolename, Equal<Required<UsersInRoles.rolename>>,
                            Or<UsersInRoles.rolename, Equal<Required<UsersInRoles.rolename>>,
                            Or<UsersInRoles.rolename, Equal<Required<UsersInRoles.rolename>>,
                            Or<UsersInRoles.rolename, Equal<Required<UsersInRoles.rolename>>
                      >>>>>>>
                    .Select(graph, graph.Accessinfo.UserName, "Administrator", "POAdmin", "POManager", "RQAdmin");
                if (roleaccess != null)
                {
                    foreach (PXResult<RQRequisition, Customer, Vendor> result in PXSelectReadonly2<RQRequisition,
            LeftJoinSingleTable<Customer, On<Customer.bAccountID, Equal<RQRequisition.customerID>>,
            LeftJoinSingleTable<Vendor, On<Vendor.bAccountID, Equal<RQRequisition.vendorID>>>>,
            Where2<Where<Customer.bAccountID, IsNull,
                                Or<Match<Customer, Current<AccessInfo.userName>>>>,
                  And<Where<Vendor.bAccountID, IsNull,
                                Or<Match<Vendor, Current<AccessInfo.userName>>>>>>>.Select(graph))
                    {
                        yield return result;
                    }
                }
                else
                {
                    EPEmployee employeeDetail = PXSelect<EPEmployee, Where<EPEmployee.userID, Equal<Required<EPEmployee.userID>>>>.Select(this._Graph, this._Graph.Accessinfo.UserID);
                    if (employeeDetail != null)
                    {
                        foreach (PXResult<RQRequisition, Customer, Vendor> result in PXSelectReadonly2<RQRequisition,
                            LeftJoinSingleTable<Customer, 
                                On<Customer.bAccountID, Equal<RQRequisition.customerID>>,
                            LeftJoinSingleTable<Vendor, 
                                On<Vendor.bAccountID, Equal<RQRequisition.vendorID>>>>,
                            Where2<Where<Customer.bAccountID, IsNull,
                                    Or<Match<Customer, Current<AccessInfo.userName>>>>,
                                And2<Where<Vendor.bAccountID, IsNull,
                                        Or<Match<Vendor, Current<AccessInfo.userName>>>>,
                                    And<Where<RQRequisition.employeeID, Equal<Required<RQRequisition.employeeID>>>>>>>
                            .Select(this._Graph, employeeDetail.BAccountID))
                        {
                            yield return result;
                        }
                    }
                }

            }
        }
        #endregion

    }



Can anyone suggest the solution?

 

Thanks..

9 replies

Forum|alt.badge.img+6
  • Captain II
  • 551 replies
  • January 2, 2023

Iโ€™d be tempted to load a copy of the data local so you can run SQL traces to see if adding an index would be helpful.

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3398 replies
  • January 3, 2023

Hi, @srikanth56  I would suggest you review the Request Profiler and check which queries taking a long time to the details and take those SQL queries and apply Non-Clustered indexes on the respective table and columns, which will solve the performance issue.


  • Author
  • Freshman I
  • 8 replies
  • January 3, 2023

Hello @ddunn  and @Naveen Boga 

The request profiler showing below tables and attached file query (The file contains the highlighted tables query).

However, the RQRequisition table already has indexes on the NoteID column, and I have added NC indexes on the VendorID and CustomerID fields, but the problem persists.

We added some custom columns to the RQRequisition table (Project, Project Task, Employee selectors), and I tried creating NC indexes on these columns as well, but no luck.

 

Could you please look over the attached query? Is there anything I'm missing?

Also, do you think any changes to the code in the custom selector will help here?

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3398 replies
  • January 3, 2023

Hi @srikanth56  As per your screenshot, these queries are not taking more than 1 second (Taking only 520 MS). I donโ€™t think are these queries are correct?

 

 

 


  • Author
  • Freshman I
  • 8 replies
  • January 3, 2023

@Naveen Boga  Is PMProject table causing issue here? 
 

 

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3398 replies
  • January 3, 2023

Yes, @srikanth56  That is correct, these queries are causing the performance issue. Let me check the attached file and let you know if I found anything.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3398 replies
  • January 3, 2023

@srikanth56  Have you added any NC indexes for the tables and verified the performance issue?


  • Author
  • Freshman I
  • 8 replies
  • January 3, 2023

Yes, @Naveen Boga. I added an NC index to the RQrequistion table's VendorID and EmployeeID, but there has been no change, and the table also contains my custom columns (Project, Project Task, and Employee field selectors). I've also created NC indexes for these custom columns, but the performance hasn't improved.


  • Freshman II
  • 4 replies
  • January 4, 2024

Hi @srikanth56 ,

Have you got any solution for this issue?

We have also faced same kind of issue and our finding is that looping and โ€œyield return resultโ€ is main cause of performance issues.

We have removed that custom selector and used standard pxselector to improve performance.

However still looking for some solution with custom selector.

If anyone can help.

thanks in advance

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings