Rest-Easy icon indicating copy to clipboard operation
Rest-Easy copied to clipboard

Add serializer for basic post data?

Open drewbaker opened this issue 7 years ago • 1 comments
trafficstars

I've been looking into performance issues on a site I'm building. It seems easy to abuse these serializes and cause infinite loops or huge query. Specially when doing things like related or siblings filters.

A common issue I am running into is this:

I need to get all child pages (to form a grid), and then get all sibling pages (to have a side menu). The current filter setup will get all child pages, and all siblings, and in the process, expand all shortcodes in the_content, which includes galleries, which means it gets all images for almost all the pages in the grid too. This is a massive query. It might even get all child pages of all siblings and do the same, I'm not sure...

A lot of the time when adding things to related, I actually only need the title, featured attachment, excerpt and relative path to a page (for building things like grids or a child page menu). Should we make a serializer that is a lightweight one, that doesn't then include things like the_content or related? Maybe rez_serialize_post_basic?

I'm not sure how that would work with Vuex when we do actually load into the detail page and the store has a record for the page, but it's missing the_content? Would it load in the missing data or not even attempt to because it thinks it has it already?

drewbaker avatar Apr 28 '18 05:04 drewbaker

I did an interesting thing in a complex shortcode (one that got all children and grand children). It would run on a lot of requests as it run through the related filters.

        global $post;

        // Abort if current post doesn't have this shortcode in it
        // to avoid rest easy from expanding this complex one on all requests
        if(  !has_shortcode($post->post_content, 'list-children') ) {
            return false;
        }

drewbaker avatar Apr 28 '18 05:04 drewbaker