lkwdwrd / code-snippets

A code/text snippet plugin for WordPress.
0 stars 0 forks source link

Performance #4

Open lkwdwrd opened 10 years ago

lkwdwrd commented 10 years ago

Want to document some ideas here since this is coming together so slowly and by the time I next sit down I may have completely forgotten this though process.

So general infrastructure is a custom post type to hold on to code snippet data, drop a shortcode into the post to set it up, and in the shortcode also drop the snippet content in as well on save so that the content is searchable.

For performance reasons, I was considering a CPT, but the complexity of that may be more than what I want for this, at least initially. Instead, it may work to parse the post right before DB insertion, if any shortcodes are present save out those IDs into post meta. When a post is loaded, it runs a query for all of the IDs it knows about in the post. This will load them up in the cache, and even without persistent caching will save them to the cache variable for that load. Then in each snippet simply run a get_post to grab the content which will pull them out of the cache.

If persistent caching is present, we almost completely take the DB out of the equation, but it's not too bad at all if it is not present.