Does it re-run script multiple times?



  • I have a handlebars/chrome-pdf report, and looking at the debug log I notice something odd...

    in the log I see three occurrences of debug: Executing script Spots - Load Data.

    Is it running the script three times (I do have headers/footers ticked and defined for Chrome-PDF ... though unchecking that option didn't make a difference), or is it because in my SQL data load (inside an async function, I have thee await for queries?), or something else ... is there anything I can/should do to optimize this?

    2019-11-25T22:58:36.232Z - info: Starting rendering request 10 (user: null)
    2019-11-25T22:58:36.239Z - info: Rendering template { name: Spots, recipe: chrome-pdf, engine: handlebars, preview: true }
    2019-11-25T22:58:36.241Z - debug: Data item not defined for this template.
    2019-11-25T22:58:36.242Z - debug: Resources not defined for this template.
    2019-11-25T22:58:36.244Z - debug: Executing script Spots - Load Data
    2019-11-25T22:58:41.954Z - debug: Base url injected: file:///C:/Users\jc\jsr
    2019-11-25T22:58:41.962Z - debug: Replaced assets ["-logo1.png"]
    2019-11-25T22:58:41.963Z - debug: Rendering engine handlebars
    2019-11-25T22:58:41.978Z - debug: Taking compiled template from engine cache
    2019-11-25T22:58:42.034Z - debug: Replaced assets ["logo2.png"]
    2019-11-25T22:58:42.037Z - debug: Executing recipe chrome-pdf
    2019-11-25T22:58:42.039Z - debug: Starting child request to render pdf header
    2019-11-25T22:58:42.041Z - info: Starting rendering request 11 (user: null)
    2019-11-25T22:58:42.042Z - info: Rendering anonymous template { recipe: html, engine: handlebars }
    2019-11-25T22:58:42.043Z - debug: Inline data specified.
    2019-11-25T22:58:42.044Z - debug: Resources not defined for this template.
    2019-11-25T22:58:42.046Z - debug: Executing script Spots - Load Data
    2019-11-25T22:58:47.776Z - debug: Base url injected: file:///C:/Users\jc\jsr
    2019-11-25T22:58:47.781Z - debug: Rendering engine handlebars
    2019-11-25T22:58:47.790Z - debug: Taking compiled template from engine cache
    2019-11-25T22:58:47.792Z - debug: Executing recipe html
    2019-11-25T22:58:47.793Z - debug: Skipping storing report.
    2019-11-25T22:58:47.794Z - debug: Executing script anonymous
    2019-11-25T22:58:47.808Z - info: Rendering request 11 finished in 5768 ms
    2019-11-25T22:58:47.811Z - debug: Starting child request to render pdf footer
    2019-11-25T22:58:47.812Z - info: Starting rendering request 12 (user: null)
    2019-11-25T22:58:47.813Z - info: Rendering anonymous template { recipe: html, engine: handlebars }
    2019-11-25T22:58:47.816Z - debug: Inline data specified.
    2019-11-25T22:58:47.816Z - debug: Resources not defined for this template.
    2019-11-25T22:58:47.818Z - debug: Executing script Spots - Load Data
    2019-11-25T22:58:53.577Z - debug: Base url injected: file:///C:/Users\jc\jsr
    2019-11-25T22:58:53.581Z - debug: Rendering engine handlebars
    2019-11-25T22:58:53.592Z - debug: Taking compiled template from engine cache
    2019-11-25T22:58:53.594Z - debug: Executing recipe html
    2019-11-25T22:58:53.594Z - debug: Skipping storing report.
    2019-11-25T22:58:53.595Z - debug: Executing script anonymous
    2019-11-25T22:58:53.608Z - info: Rendering request 12 finished in 5796 ms
    2019-11-25T22:58:53.611Z - debug: Converting with chrome HeadlessChrome/76.0.3803.0 using chrome-pool strategy
    2019-11-25T22:58:53.858Z - debug: Running chrome with params {"printBackground":true,"format":"A4","marginTop":"2.54cm","marginRight":"2.54cm","marginBottom":"2.54cm","marginLeft":"2.54cm","displayHeaderFooter":true,"landscape":false,"width":"21cm","height":"29.7cm","headerTemplate":"<html>\r\n<head><base href='file:///C:/Users\\jc\\jsr' />\r\n    <style>\r\n        /* defining explicit font-size solves the scaling issue */\r\n\r\n        html,\r\n        body {\r\n            font-family: calibri;\r\n            font-size: 10pt;\r\n        }\r\n        body {\r\n            margin-left: 2cm;\r\n            margin-right: 2cm;\r\n            margin-bottom: 2cm;\r\n        }\r\n    </style>\r\n</head>\r\n\r\n<body>\r\n</body>\r\n\r\n</html>","footerTemplate":"<html>\r\n\r\n<head><base href='file:///C:/Users\\jc\\jsr' />\r\n    <style>\r\n        /* defining explicit font-size solves the scaling issue */\r\n\r\n        html,\r\n        body {\r\n            font-family: calibri;\r\n            font-size: 10pt;\r\n        }\r\n\r\n        .container {\r\n            width: 100%;\r\n            margin-left: 0cm;\r\n            margin-right: 2.54cm;\r\n        }\r\n\r\n        .ftr-right {\r\n            text-align: right;\r\n            float: right;\r\n        }\r\n\r\n        .ftr-left {\r\n            float: left;\r\n            text-align: left;\r\n        }\r\n    </style>\r\n</head>\r\n\r\n<body>\r\n    <div class=\"container\">\r\n        <span class=\"ftr-left\">&copy; &nbsp;2019</span>\r\n        <span class=\"ftr-right\">Page\r\n            <span class=\"pageNumber\"></span> of\r\n            <span class=\"totalPages\"></span>\r\n        </span>\r\n    </div>\r\n</body>\r\n\r\n</html>","waitForJS":false,"margin":{"top":"2.54cm","right":"2.54cm","bottom":"2.54cm","left":"2.54cm"}}
    2019-11-25T22:58:54.225Z - debug: Skipping storing report.
    2019-11-25T22:58:54.227Z - debug: Executing script anonymous
    2019-11-25T22:58:54.250Z - info: Rendering request 10 finished in 18018 ms




  • thanks! seems a little odd it would do that (especially with the header/foot checkmark turned off), but the logic speeds up my chrome-pdf reports considerably (now almost as quick as generating the Excel ones, which are really quick!)



  • It is odd, but changing it would be breaking.

    We have some proposals here, so let's see how we get out of this situation
    https://github.com/jsreport/jsreport/issues/657



  • what would life be without interesting quirks :)
    knowing the code workaround is good, and both the proposed solutions make sense (adding the options in v2 defaulting to false would surface the solution, and then in v3 flipping the default for new templates - especially surfaced with the checkbox in Studio - would avoid confusing people with the change)


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.