corcel: Post method __get extremely slow

I’ve been having some troubles with the __get($key) method in the Post model.

It makes a queries looking for metas every time a key is not found in the post model. This is very time consuming and avoids any possible cache (I have a cache and still have like 750 queries to meta files)

screen shot 2016-02-12 at 01 06 02

I’d suggest another approach, removing the __get method and getting all the needed information with accessors like done before.

What do you think?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

I have had a similar issue where the database was being hit when you would do the following:

$post = Post::query();

Which you might want to do start a fresh query chain. You’d end up with queries like this:

select 
  * 
from 
  `wp_postmeta` 
where 
  `wp_postmeta`.`post_id` is null 
  and `wp_postmeta`.`post_id` is not null

That will return an empty set, of course, but it’s still unnecessary to hit the database when you know it shouldn’t be returning anything, as is the case where you have a new instance of Post and no ID to go along with it.

I’ve created two patches with potential solutions to the issue and since they might intersect with some of the issues here I figured I’d post the patches here rather than start a new issue ticket.

I’m more partial to the second solution, but neither of them are perfect. I just figured I’d post them here for discussion to see if anyone had a better solution;