Jump to content

hook after page is displayed?


bernhard
 Share

Recommended Posts

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

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.

  • Like 2
Link to comment
Share on other sites

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

  • 2 weeks later...

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...

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...