Expensive to call user function

8 posts, 0 answers
  1. Rick
    Rick avatar
    17 posts
    Member since:
    Sep 2011

    Posted 08 Feb Link to this post

    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.

  2. Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 11 Feb Link to this post

    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
  3. DevCraft banner
  4. Rick
    Rick avatar
    17 posts
    Member since:
    Sep 2011

    Posted 11 Feb in reply to Nasko Link to this post

    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.

  5. Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 16 Feb Link to this post

    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
  6. Rick
    Rick avatar
    17 posts
    Member since:
    Sep 2011

    Posted 17 Feb in reply to Nasko Link to this post

    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

  7. Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 18 Feb Link to this post

    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
  8. Rick
    Rick avatar
    17 posts
    Member since:
    Sep 2011

    Posted 18 Feb in reply to Nasko Link to this post

    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

  9. Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 23 Feb Link to this post

    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
Back to Top
DevCraft banner