簡體   English   中英

在自定義屏幕中查看委托時需要幫助

[英]Need help in view delegate in custom screen

我們創建了一個自定義屏幕,它根據過濾條件顯示銷售數據列表,例如(今天、昨天、本周、本月、本季度、今年),我們為此創建了 SQL 視圖,然后從我們創建的 VIEW 和 DAC 和在自定義屏幕中使用它。 我們的屏幕中也有過濾器。 對於過濾條件,我們使用視圖委托並返回數據。 問題是為什么屏幕加載 2K 記錄需要 70 秒左右的時間太長。 使用視圖委托會降低加載數據的速度。 我們可以使用 GI go,但我們需要在 GRID 中顯示圖像,因此我們選擇了自定義屏幕,並且我們在 header 中有一些報告按鈕,用於打印報告。 因為我們不能在 GI 中顯示圖像,所以我們選擇了這個。

您看到的緩慢很可能是由兩個原因共同造成的。

  1. 當您使用 BQL 視圖時,它實際上只請求您在屏幕上看到的記錄數。 例如,如果您有帶有分頁的網格並且頁面上只有 20 條記錄可見,則 SQL select 將具有 TOP 20 限制。 但是,一旦您擁有 select 委托,該優化將停止工作,因為框架不知道您想對 select 的數據做什么。 這里的解決方案是使用SelectWithViewContextDelegateResult返回 object 而不是常規的 select。 在這種情況下,用戶過濾、分頁和排序保留在 select 中。 (僅當屏幕上的結果記錄與您 select 的記錄以 1 對 1 相關時使用此方法。如果您使用任何類型的聚合或插入來自 2 個不同 select 的記錄,則該方法不起作用)

例子:

protected virtual IEnumerable ardocumentlist()
{
PXSelectBase<BalancedARDocument> cmd =
    new PXSelectJoinGroupBy<BalancedARDocument,
        ...
        OrderBy<Asc<BalancedARDocument.docType, //Set necessary sorting fields: use the key fields
        Asc<BalancedARDocument.refNbr>>>> //Set necessary sorting fields: use the key fields
        (this);

PXDelegateResult delegResult = new PXDelegateResult
{
    IsResultFiltered = true, //set these fields to indicate that the result does not need re-filtering, resorting and re-paging
    IsResultTruncated = true,
    IsResultSorted = true
}

foreach (PXResult<BalancedARDocument> res_record in cmd.SelectWithViewContext())
{
    // add the code to process res_record
    delegResult.Add(res_record);
}
return delegResult;
}
  1. 可能您的表上沒有正確的索引,因為即使您 select 一次所有 2k 記錄也不應該導致 70 秒的加載時間。 Recommendation here would be to use the request profiler to catch the exact SQL generated ( https://help-2020r2.acumatica.com/Help?ScreenId=ShowWiki&pageid=e4c450bb-86bc-4fb2-b7e6-1f715abe3c8b ) and execute the SQL in MS SQL 管理工作室,帶有“包括實際執行計划”選項( https://docs.microsoft.com/en-us/sql/relational-databases/performance/display-an-actual-execution-plan?view=sql-server-版本 15 )。 通常在這種模式下,MS SQL 服務器會建議加快查詢執行所需的索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM