bernhard Posted April 28, 2017 Share Posted April 28, 2017 hi all, i have a complex table where it takes 20sec to generate the data. i use markupcache to reduce loading time if nothing has changed since the last display. now it would be great to be able to regenerate this cache everytime a page of a special template was saved. i know how to do that via pages::saved but thats not exactly what i want because then it takes 20sec to display the page after saving it. is it possible to execute this code AFTER the page is rendered and sent to the visitor? I'm working only in the admin, so i tried ProcessPageView::finished() but that also delays the output of the page render. any ideas? is this technically possible or would i have to use a cronjob checking for changes every x seconds? other question: can i limit the amout of CPU used somehow? the problem is, that the server does not react while calculating my table data... thank you for your help! Link to comment Share on other sites More sharing options...
tpr Posted April 28, 2017 Share Posted April 28, 2017 What about an Ajax call on doc or window ready? 2 Link to comment Share on other sites More sharing options...
abdus Posted April 28, 2017 Share Posted April 28, 2017 Use exec() to run a background task that curls your page maybe? http://stackoverflow.com/a/4628279 3 Link to comment Share on other sites More sharing options...
bernhard Posted April 28, 2017 Author Share Posted April 28, 2017 1 hour ago, tpr said: What about an Ajax call on doc or window ready? so simple, i didn't think of that! thank you Link to comment Share on other sites More sharing options...
tpr Posted April 28, 2017 Share Posted April 28, 2017 haha, I was afraid I wrote bs 1 Link to comment Share on other sites More sharing options...
Macrura Posted April 28, 2017 Share Posted April 28, 2017 one thing i did for a complex table was - single row data is cached (wire cache) - entire table is cached (wirecache) from the row data - the json is used to create the table itself (data tables). if a single row changes, that row's cache is refreshed and the whole table, but this was fast because all of the other rows didn't need to be re-calculated. also in my case, each row had some pretty complex rendering functions that needed to run, so this was the best solution i came up with; and wirecache worked really well! in testing datatables, for my use case, inline json was the fastest to render, when compared with table markup and ajax. 2 Link to comment Share on other sites More sharing options...
bernhard Posted April 28, 2017 Author Share Posted April 28, 2017 yeah, i also thought about that, but caching the whole table is a lot easier in my scenario and is good enough regarding user experience i'm using datatables with the ajax option. i had some bad performance issues using the markup/html option first. the ajax option is nice to show a loading indicator and to be able to do an easy update of the data - as simple as DataTable().ajax.reload() thank you for all your feedback Link to comment Share on other sites More sharing options...
bernhard Posted May 8, 2017 Author Share Posted May 8, 2017 just wanted to mention that there could be another option if somebody is not happy with an ajax solution: Quote HOW LAZY CRON WORKS When installed, LazyCron hooks into ProcessWire's ProcessPageView::finished() method. This ensures that the scheduled tasks are executed after the pageview has already been delivered rather than before or during it. This hopefully avoids any perceived slowdown if the scheduled tasks take time. https://processwire.com/api/modules/lazy-cron/ not enough time to investigate further, but i wanted to put the reference here... 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now