You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a page that display all the changes made by a user.
For this use case I added the following enhancement to speed up considerably my revision page.
I created a model extending \Venturecraft\Revisionable\Revision and added some relation like:
And in GetValue function from \Venturecraft\Revisionable\Revision.php I added this:
+ $item = ($this->relations[$which . "_" . $related_model] ?? null);
+ if(!$item)
+ {
$related_class = $main_model->$related_model()->getRelated();
// Finally, now that we know the namespace of the related model// we can load it, to find the information we so desire$item = $related_class::find($this->$which_value);
+ }
Finally I load my revisions like this:
// Example $res = \App\Models\MyRevision::where('user_id', $user->id)->get();
$res->where('revisionable_type', 'App\Models\User')->load('user'); // eager load user model$res->where('key', 'user_type_id')->load('old_user_type'); // eager load related model (like old_relation_a)$res->where('key', 'user_type_id')->load('new_user_type'); // eager load related model (like new_relation_a)
This way I can speed up my load page and decrease considerably the number of queries.
I will be great to add it, let me know if you want this and I can create a PR.
(I actually have this change in my model, but I have to reuse most of the parent method)
The text was updated successfully, but these errors were encountered:
I have a page that display all the changes made by a user.
For this use case I added the following enhancement to speed up considerably my revision page.
I created a model extending \Venturecraft\Revisionable\Revision and added some relation like:
And in GetValue function from \Venturecraft\Revisionable\Revision.php I added this:
Finally I load my revisions like this:
This way I can speed up my load page and decrease considerably the number of queries.
I will be great to add it, let me know if you want this and I can create a PR.
(I actually have this change in my model, but I have to reuse most of the parent method)
The text was updated successfully, but these errors were encountered: