This is a migrated thread and some comments may be shown as answers.

Expensive to call user function

7 Answers 219 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 2
Rick asked on 08 Feb 2016, 09:30 PM

I have a user function that returns an object with a lot of calculated fields that are expensive to call each time. Is there a way to call the function one time and save the results so that it doesn't get called multiple times as I display the fields on the report?

There are at least 10 individual text fields that are displayed on the report that all come from the user function.

 

Thanks.

7 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 11 Feb 2016, 12:09 PM
Hello Rick,

The user function will be called as many times as there are expressions in the report which are calling it. This is the behavior of the user functions by design. If you share more information on the user function definition we might be able to suggest ways to optimize the code inside, or replace the user function with another functionality.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Rick
Top achievements
Rank 2
answered on 11 Feb 2016, 05:52 PM

Yes, I see that it's called multiple times. I was hoping to save the results of the call so that I can display multiple fields with data that comes from the user function. In my case, the user function is returning an object with many fields such as ProcessDate, Status, StatusDate, Description, Title, Summary...

The user function is getting this data from both sql and info in a redis cache and would not easily be added to the sql stored procedure that drives the report.

I've also tried binding the report to the object directly as a second data source, but no matter what I've done, the wizard doesn't show any of my business objects.

0
Nasko
Telerik team
answered on 16 Feb 2016, 09:16 AM
Hello Rick,

You can call the user function once and store the result inside a property of the report, or a report parameter. The approach is demonstrated in the attached project.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Rick
Top achievements
Rank 2
answered on 17 Feb 2016, 09:04 PM

Thanks for the code, however, I think there are a few issues.

1. When I create a parameter, my choices of type do not include object. In my description, I mentioned that the user function returns an object with many fields.

2. Each row of the report needs to call the user function with a different parameters. It looked like I could not reference the field values when creating the report parameter.

Any other ideas? This might be a show-stopper for our review of Telerik Reporting.

Thanks,

Rick

0
Nasko
Telerik team
answered on 18 Feb 2016, 12:44 PM
Hello Rick,

There are other possible solutions which are out of the scope of Telerik Reporting. For example, you can create a single complex object with precalculated data for all of the current report class instances and reuse the object inside the user function method. Attached you can find a sample project demonstrating the approach.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Rick
Top achievements
Rank 2
answered on 18 Feb 2016, 10:02 PM

Two questions again:
1. Does this technique work using the stand-alone report definitions (trdx files)?

2. In my case, the expensive object needs to be reevaluated each time the group header changes. Is that possible?

Thanks,

Rick

0
Nasko
Telerik team
answered on 23 Feb 2016, 01:21 PM
Hello Rick,

1. The Standalone Report Designer can work only with XML report definitions (TRDX). The technique is not applicable to TRDX reports.

2. You can call another user function inside the group header and trigger the re-evaluation using code when the value of a field changes.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Rick
Top achievements
Rank 2
Answers by
Nasko
Telerik team
Rick
Top achievements
Rank 2
Share this question
or