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 df9676b6
authored
Sep 19, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed memory leak by correctly unbinding client listeners
1 parent
cb5f8b1f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
lib/sequelize/connector-manager.js
lib/sequelize/query.js
lib/sequelize/connector-manager.js
View file @
df9676b
...
...
@@ -21,7 +21,7 @@ ConnectorManager.prototype.connect = function() {
database
:
this
.
config
.
database
})
this
.
client
.
setMaxListeners
(
Math
.
pow
(
2
,
32
)
-
1
)
this
.
client
.
setMaxListeners
(
this
.
maxConcurrentQueries
)
}
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
...
...
lib/sequelize/query.js
View file @
df9676b
var
Utils
=
require
(
"./utils"
)
var
Query
=
module
.
exports
=
function
(
client
,
callee
,
options
)
{
var
self
=
this
this
.
client
=
client
this
.
callee
=
callee
this
.
options
=
options
||
{}
this
.
client
.
on
(
'error'
,
function
(
err
)
{
self
.
onFailure
(
err
)
})
this
.
bindClientFunction
=
function
(
err
)
{
self
.
onFailure
(
err
)
}
}
Utils
.
addEventEmitter
(
Query
)
...
...
@@ -14,6 +11,8 @@ Query.prototype.run = function(query) {
var
self
=
this
this
.
sql
=
query
this
.
bindClient
()
if
(
this
.
options
.
logging
)
console
.
log
(
'Executing: '
+
this
.
sql
)
...
...
@@ -24,10 +23,18 @@ Query.prototype.run = function(query) {
return
this
}
Query
.
prototype
.
bindClient
=
function
()
{
this
.
client
.
on
(
'error'
,
this
.
bindClientFunction
)
}
Query
.
prototype
.
unbindClient
=
function
()
{
this
.
client
.
removeListener
(
'error'
,
this
.
bindClientFunction
)
}
Query
.
prototype
.
onSuccess
=
function
(
query
,
results
,
fields
)
{
var
result
=
this
.
callee
,
self
=
this
// add the inserted row id to the instance
if
(
this
.
callee
&&
(
query
.
indexOf
(
'INSERT INTO'
)
==
0
)
&&
(
results
.
hasOwnProperty
(
'insertId'
)))
this
.
callee
[
this
.
callee
.
definition
.
autoIncrementField
]
=
results
.
insertId
...
...
@@ -41,9 +48,11 @@ Query.prototype.onSuccess = function(query, results, fields) {
result
=
(
result
.
length
==
0
)
?
null
:
result
[
0
]
}
this
.
unbindClient
()
this
.
emit
(
'success'
,
result
)
}
Query
.
prototype
.
onFailure
=
function
(
err
)
{
this
.
unbindClient
()
this
.
emit
(
'failure'
,
err
,
this
.
callee
)
}
\ No newline at end of file
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