Jump to content

Page fetch performance and fetching individual page field values


Rob
 Share

Recommended Posts

The site I'm working on is built using a separate framework and purely fetch page data via the ProcessWire API.

I'm using a cache component and testing the modified date of a page to test whether a fresh page needs to be rendered or the cache copy is OK. The issue I have is that I don't know whether the entire page data is being fetched at the point at which I call the API $pages->get() method, or whether each field is fetched on-the-fly as it is referenced.

There is more than likely a performance increase by the time saved NOT injecting page data into a template, but what I'd really like is to be able to ONLY fetch the modified field from the page so the cache code is as optimised as possible.

Can anyone shed any light on this, or advise how I can just fetch the page->modified field using the PW API? I could sidestep the API but this is a bit kludgey and I'd rather keep things clean.

Thanks!

Link to comment
Share on other sites

The issue I have is that I don't know whether the entire page data is being fetched at the point at which I call the API $pages->get() method, or whether each field is fetched on-the-fly as it is referenced.

Only fields with the 'autojoin' option set are fetched when a page is loaded. All other fields are fetched on demand. Meaning, $page->body won't actually be retrieved from the DB until you access $page->body. Most fields can have the autojoin option set if you want it (Setup > Fields > your field > Advanced > Autojoin). However, I recommend using that sparingly and only on fields that are used every time you load the Page. The 'title' field is a good example of a field that should be autojoin.

ProcessWire does not keep separate modification dates for each field. Though it's feasible that it could. If you went into the DB and added a timestamp field to each field_* table, that's essentially what it would do since MySQL automatically sets a timestamp field on every update.

Can anyone shed any light on this, or advise how I can just fetch the page->modified field using the PW API? I could sidestep the API but this is a bit kludgey and I'd rather keep things clean.

I'm not sure I understand this question, as you can access $page->modified already. Likewise, you can retrieve pages from a selector using the modified property. For instance, if you wanted to retrieve all pages modified in the last day:

$items = $pages->find("modified>=-1 DAY"); 
Link to comment
Share on other sites

Thanks for the help.

I've done some testing and fiddling and it looks like, for best performance, I can execute an SQL query directly against wire('db') to check modification date of a page row and then either utilise the cache or fetch entire fresh page from DB. It gave a performance gain of around 20%, nothing earth-shattering. I won't know for sure until it's tested in a live environment with real traffic (rather than on my local machine), but good to know what's possible.

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