Fixing periodic connection timeout
This commit is contained in:
parent
085e351245
commit
ccb5b5d7a2
@ -26,9 +26,9 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var mysql = require('mysql');
|
var mysql = require('mysql');
|
||||||
var connection = null;
|
var pool = null;
|
||||||
|
|
||||||
function innerProduct(values1, values2) {
|
function innerProduct(values1, values2) {
|
||||||
var result = 0.0;
|
var result = 0.0;
|
||||||
@ -171,7 +171,7 @@ function buildHints(data, searchParams, minScore, keyword, range, steps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadDb(params) {
|
function loadDb(params) {
|
||||||
connection = mysql.createConnection(params);
|
pool = mysql.createPool(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addKeyword(query, callback) {
|
function addKeyword(query, callback) {
|
||||||
@ -193,7 +193,7 @@ function addKeyword(query, callback) {
|
|||||||
features.atmosphere || 0.0
|
features.atmosphere || 0.0
|
||||||
];
|
];
|
||||||
|
|
||||||
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
|
pool.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
|
||||||
callback({
|
callback({
|
||||||
keyword: keyword,
|
keyword: keyword,
|
||||||
success: err === null
|
success: err === null
|
||||||
@ -204,7 +204,7 @@ function addKeyword(query, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeKeyword(query, callback) {
|
function removeKeyword(query, callback) {
|
||||||
connection.query('DELETE FROM keywords WHERE name=? AND name NOT IN (SELECT name FROM presets)', [query.keyword], function(err, fields) {
|
pool.query('DELETE FROM keywords WHERE name=? AND name NOT IN (SELECT name FROM presets)', [query.keyword], function(err, fields) {
|
||||||
callback({
|
callback({
|
||||||
keyword: query.keyword,
|
keyword: query.keyword,
|
||||||
success: err === null && fields.affectedRows > 0
|
success: err === null && fields.affectedRows > 0
|
||||||
@ -213,7 +213,7 @@ function removeKeyword(query, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getKeywords(callback) {
|
function getKeywords(callback) {
|
||||||
connection.query('SELECT * FROM keywords', function(err, rows) {
|
pool.query('SELECT * FROM keywords', function(err, rows) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@ -234,7 +234,7 @@ function getKeywords(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getRecords(callback) {
|
function getRecords(callback) {
|
||||||
connection.query('SELECT * FROM reviews', function(err, rows) {
|
pool.query('SELECT * FROM reviews', function(err, rows) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,10 @@ function main(staticFiles, port) {
|
|||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
search.loadDb({
|
search.loadDb({
|
||||||
'host': 'localhost',
|
connectionLimit: 10,
|
||||||
'user': 'hscd',
|
database: 'hscd',
|
||||||
'database': 'hscd'
|
host: 'localhost',
|
||||||
|
user: 'hscd'
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use('/get_keywords', function(req, res) {
|
app.use('/get_keywords', function(req, res) {
|
||||||
|
Loading…
Reference in New Issue
Block a user