Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
f36446bd
Commit
f36446bd
authored
Oct 05, 2012
by
Vinícius Fragoso
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving laravel relationship performance
parent
4f8a6724
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
24 deletions
+40
-24
belongs_to.php
laravel/database/eloquent/relationships/belongs_to.php
+8
-7
has_many.php
laravel/database/eloquent/relationships/has_many.php
+10
-6
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+10
-6
has_one.php
laravel/database/eloquent/relationships/has_one.php
+12
-5
No files found.
laravel/database/eloquent/relationships/belongs_to.php
View file @
f36446bd
...
...
@@ -87,16 +87,17 @@ class Belongs_To extends Relationship {
{
$foreign
=
$this
->
foreign_key
();
foreach
(
$children
as
&
$child
)
$parents_hash
=
array
();
foreach
(
$parents
as
$parent
)
{
$parent
=
array_first
(
$parents
,
function
(
$k
,
$v
)
use
(
&
$child
,
$foreign
)
{
return
$v
->
get_key
()
==
$child
->
$foreign
;
});
$parents_hash
[
$parent
->
get_key
()]
=
$parent
;
}
if
(
!
is_null
(
$parent
))
foreach
(
$children
as
$child
)
{
if
(
array_key_exists
(
$child
->
$foreign
,
$parents_hash
))
{
$child
->
relationships
[
$relationship
]
=
$parent
;
$child
->
relationships
[
$relationship
]
=
$parent
s_hash
[
$child
->
$foreign
]
;
}
}
}
...
...
laravel/database/eloquent/relationships/has_many.php
View file @
f36446bd
...
...
@@ -91,14 +91,18 @@ class Has_Many extends Has_One_Or_Many {
{
$foreign
=
$this
->
foreign_key
();
foreach
(
$parents
as
&
$parent
)
$children_hash
=
array
();
foreach
(
$children
as
$child
)
{
$matching
=
array_filter
(
$children
,
function
(
$v
)
use
(
&
$parent
,
$foreign
)
{
return
$v
->
$foreign
==
$parent
->
get_key
();
});
$children_hash
[
$child
->
$foreign
][]
=
$child
;
}
$parent
->
relationships
[
$relationship
]
=
array_values
(
$matching
);
foreach
(
$parents
as
$parent
)
{
if
(
array_key_exists
(
$parent
->
get_key
(),
$children_hash
))
{
$parent
->
relationships
[
$relationship
]
=
$children_hash
[
$parent
->
get_key
()];
}
}
}
...
...
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
f36446bd
...
...
@@ -328,14 +328,18 @@ class Has_Many_And_Belongs_To extends Relationship {
{
$foreign
=
$this
->
foreign_key
();
foreach
(
$parents
as
&
$parent
)
$children_hash
=
array
();
foreach
(
$children
as
$child
)
{
$matching
=
array_filter
(
$children
,
function
(
$v
)
use
(
&
$parent
,
$foreign
)
{
return
$v
->
pivot
->
$foreign
==
$parent
->
get_key
();
});
$children_hash
[
$child
->
pivot
->
$foreign
][]
=
$child
;
}
$parent
->
relationships
[
$relationship
]
=
array_values
(
$matching
);
foreach
(
$parents
as
$parent
)
{
if
(
array_key_exists
(
$parent
->
get_key
(),
$children_hash
))
{
$parent
->
relationships
[
$relationship
]
=
$children_hash
[
$parent
->
get_key
()];
}
}
}
...
...
laravel/database/eloquent/relationships/has_one.php
View file @
f36446bd
...
...
@@ -38,14 +38,21 @@ class Has_One extends Has_One_Or_Many {
{
$foreign
=
$this
->
foreign_key
();
foreach
(
$parents
as
&
$parent
)
$children_hash
=
array
();
foreach
(
$children
as
$child
)
{
$matching
=
array_first
(
$children
,
function
(
$k
,
$v
)
use
(
&
$parent
,
$foreign
)
if
(
array_key_exists
(
$child
->
pivot
->
$foreign
,
$children_hash
)
)
{
return
$v
->
$foreign
==
$parent
->
get_key
();
});
continue
;
}
$children_hash
[
$child
->
pivot
->
$foreign
]
=
$child
;
}
$parent
->
relationships
[
$relationship
]
=
$matching
;
foreach
(
$parents
as
$parent
)
{
if
(
array_key_exists
(
$parent
->
get_key
(),
$children_hash
))
$parent
->
relationships
[
$relationship
]
=
$children_hash
[
$parent
->
get_key
()];
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment