Closed ysshir closed 3 years ago
Wow, there is another fix for another issue..
Actually, this may be the same issue... Can you test again with last changes on 1.9 ?
@AdamSGit
I’d love to but because of my poor English, I’m not sure the actual previous problem... can you give me the sample for the problem? or the test code you used?? I think we can do better communication in PHP than English. :-)
I said that maybe your issue was fixed by the latest changes. Can you update your installation to date and test your issue again, see if it is resolved.
oiic but none of my problems are resolved.
Your 2nd test is only true of you have object caching active. If not, new objects are created for every result.
@WanWizard
ah, sorry for my poor understanding.
$grand_children[1]->child->id
= 1
$grand_children[2]->child->id
= 1
but the child instances are created each time. in from_array
function.
because from_array
function doesn't care the caches..
I see the problem.
The cache check in hydration doesn't deal with duplicate objects created in the same query. Because objects are only created for new results once hydration is completed.
I'll have to think about this, as this is the most time consuming part of processing a query, it needs to remain very efficient.
How to check if the singular relation is loaded or not, you use instanceof Model
.
but most of the time, the variable contains array, (not if it is cached objects)
so it is impossible to detect.
once I added variable for checking if it singular or not for parent.
but in from_array
method, it is not considering the caching.
so I had to change the approach.
so I changed to create instances in the process_row
, not after that.
it is quite big change, I think.
Because you choose to use from_array
method to initialize.
anyway If you have any other way to resolve my issues, I appreciate to follow.
from_array()
isn't used in process_row()
.
The old (1.8.x) code used object creation on the fly during hydration, which made the logic long and complex, and therefore slow. This was the reason for the rewrite, which now hydrates first, and converts later using Model::forge()
.
The reason for doing this is that from_array()
in Model::forge()
works recursive, so that saves a lot of tracking logic during hydration.
I want to avoid a revert to the old complex code at all costs. That requires some thinking and testing, not something to hurriedly hack in...
It is probably the best to add a cache check in from_array()
before it calls Model::forge()
to create a new object from array data.
from_array isn't used in process_row.
yeah, I know, the method is used in constructor,
and you forge instances after process_row
, right?
but the change makes instanceof Model
not to work as well.
I'm pretty sure why you change the process_row
so I tried to less forge
in process_row
with closure.
hmm I should study English
Want me to help with that Harro ?
It is probably the best to add a cache check in from_array()
yeah, I agree with this.
and I also would like you to consider if we don't need the cached objects for results with from_cache(false)
.
As I said, it needs a proper think, because I see more issues with the current code.
For example, consider this:
$a = Model_Test::find(1);
$b = Model_Test::forge([ 'id' => 1 ]));
echo $a === $b ? "True" : "False";
what is the result? what should the result be if caching is enabled?
This might lead to Model::forge()
having to return a cached object, which currently it can't as it always returns a new instance.
Also, existing model objects could be in an is_changed()
state, so it's data must not be overwritten (and I think this now happens).
But the result could also contain related objects that aren't loaded with the cached object, so they should be added, and they could also be in a changed state.
Want me to help with that Harro ?
Two ( actually, one-and-a-half :smirk: ) brains know more than one....
I think we need to compromise on somewhere.
and we have to use models with caution. for editing, for reference,
but what I thought was same record should be one instance in one query.
It seem like you do have some left, tho :-)
Will think about it.
Consistency is important. If it is sometimes the same, sometimes not, we'll be in a heap of trouble...
Maybe the way to load the cached object in one request or task is wrong. must be simple.
@AdamSGit This one still needs adressing, but I think that requires moving cache lookups from process_row()
to from_array()
, which is a major undertaking. I don't want to forge objects in process_row()
, that process should be as quick as possible.
Alright. What about the break you mentioned with relations being set as EAV ?
Is fixed too.
tables..
parent
child
grand_child
Models...
problems
I fixed 2 above problems.
I tried to create arrays in process_row(), but I noticed 2nd problem. therefore the fix became quite big.