Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 3c71d152
authored
Feb 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve performance in cases where we have a single primary key
1 parent
d9debb39
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
10 deletions
lib/dialects/abstract/query.js
lib/dialects/abstract/query.js
View file @
3c71d15
...
...
@@ -230,7 +230,11 @@ module.exports = (function() {
// Queries with include
}
else
if
(
this
.
options
.
hasJoin
===
true
)
{
results
=
groupJoinData
(
results
,
this
.
options
,
{
results
=
groupJoinData
(
results
,
{
daoFactory
:
this
.
callee
,
includeMap
:
this
.
options
.
includeMap
,
includeNames
:
this
.
options
.
includeNames
},
{
checkExisting
:
this
.
options
.
hasMultiAssociation
})
...
...
@@ -338,7 +342,22 @@ module.exports = (function() {
,
calleeData
,
child
,
calleeDataIgnore
=
[
'__children'
]
,
parseChildren
=
function
(
result
)
{
_
.
each
(
result
.
__children
,
function
(
children
,
key
)
{
result
[
key
]
=
groupJoinData
(
children
,
(
includeOptions
.
includeMap
&&
includeOptions
.
includeMap
[
key
]),
options
)
})
delete
result
.
__children
},
primaryKeyAttribute
// Identify singular primaryKey attribute for equality check (if possible)
if
(
includeOptions
.
daoFactory
.
primaryKeyAttributes
.
length
===
1
)
{
primaryKeyAttribute
=
includeOptions
.
daoFactory
.
primaryKeyAttributes
[
0
]
}
else
if
(
includeOptions
.
daoFactory
.
rawAttributes
.
id
)
{
primaryKeyAttribute
=
'id'
}
// Ignore all include keys on main data
if
(
includeOptions
.
includeNames
)
{
calleeDataIgnore
=
calleeDataIgnore
.
concat
(
includeOptions
.
includeNames
)
}
...
...
@@ -349,10 +368,13 @@ module.exports = (function() {
// If there are :M associations included we need to see if the main result of the row has already been identified
existingResult
=
options
.
checkExisting
&&
_
.
find
(
results
,
function
(
result
)
{
if
(
calleeDataIgnore
)
{
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
calleeData
)
// If we can, detect equality on the singular primary key
if
(
primaryKeyAttribute
)
{
return
result
[
primaryKeyAttribute
]
===
calleeData
[
primaryKeyAttribute
]
}
return
Utils
.
_
.
isEqual
(
result
,
calleeData
)
// If we can't identify on a singular primary key, do a full row equality check
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
calleeData
)
})
if
(
!
existingResult
)
{
...
...
@@ -377,14 +399,17 @@ module.exports = (function() {
}
}
}
// parseChildren in same loop if no duplicate values are possible
if
(
!
options
.
checkExisting
)
{
parseChildren
(
existingResult
)
}
})
results
.
forEach
(
function
(
result
)
{
_
.
each
(
result
.
__children
,
function
(
children
,
key
)
{
result
[
key
]
=
groupJoinData
(
children
,
(
includeOptions
.
includeMap
&&
includeOptions
.
includeMap
[
key
]),
options
)
})
delete
result
.
__children
})
// parseChildren after row parsing if duplicate values are possible
if
(
options
.
checkExisting
)
{
results
.
forEach
(
parseChildren
)
}
return
results
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment