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)
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)
I have had a similar issue where the database was being hit when you would do the following:
Which you might want to do start a fresh query chain. You’d end up with queries like this:
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 noID
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.
ID
yet, we just pass the__get
up toparent
.PostMetaCollection
and assign it to thePost
to mimic what we would have received from the database if we did have anID
.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;